Implemented new Userfield type "Select list" (closes #325)

This commit is contained in:
Bernd Bestel
2019-09-17 19:11:06 +02:00
parent bbd5ce1dc4
commit 0c27157db6
11 changed files with 44 additions and 13 deletions

View File

@@ -112,3 +112,8 @@ FindAllObjectsInArrayByPropertyValue = function(array, propertyName, propertyVal
return returnArray;
}
$.fn.hasAttr = function(name)
{
return this.attr(name) !== undefined;
};

View File

@@ -14,7 +14,7 @@ Grocy.Components.UserfieldsForm.Save = function(success, error)
var jsonData = { };
$("#userfields-form .userfield-input").each(function()
$("#userfields-form .userfield-input").not("div").each(function()
{
var input = $(this);
var fieldName = input.attr("data-userfield-name");
@@ -28,6 +28,10 @@ Grocy.Components.UserfieldsForm.Save = function(success, error)
jsonData[fieldName] = "1";
}
}
else if ($(this).hasAttr("multiple"))
{
jsonData[fieldName] = $(this).val().join(",");
}
else
{
jsonData[fieldName] = fieldValue;
@@ -70,6 +74,11 @@ Grocy.Components.UserfieldsForm.Load = function()
{
input.prop("checked", true);
}
else if (input.hasAttr("multiple"))
{
input.val(value.split(","));
$(".selectpicker").selectpicker("render");
}
else
{
input.val(value);

View File

@@ -72,7 +72,7 @@ $("#type").on("change", function(e)
{
var value = $(this).val();
if (value === "preset-list")
if (value === "preset-list" || value === "preset-checklist")
{
$("#config").parent().removeClass("d-none");
$("#config-hint").text(__t("A predefined list of values, one per line"));