Skip to content

Commit

Permalink
Fix save and loading of fields select multiple
Browse files Browse the repository at this point in the history
  • Loading branch information
partulaj committed Feb 28, 2023
1 parent 5a47eaf commit b6f0507
Showing 1 changed file with 30 additions and 17 deletions.
47 changes: 30 additions & 17 deletions Resources/public/js/KilikTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ function KilikTable(id, path, options) {
"sortColumn": this.sortColumn,
"sortReverse": this.sortReverse,
"filters": $("form[name=" + this.getFormName() + "]").serializeArray().reduce(function (obj, item) {
obj[item.name] = item.value;
obj[item.name] = $('[name="'+item.name+'"]').val();
return obj;
}, {}),
"hiddenColumns": this.hiddenColumns,
Expand All @@ -275,23 +275,36 @@ function KilikTable(id, path, options) {
this.rowsPerPage = options.rowsPerPage;
this.sortColumn = options.sortColumn;
this.sortReverse = options.sortReverse;
$("form[name='" + this.getFormName() + "'] [name]").each(function (index, elem) {
var name = $(elem).attr("name")
if (options.filters[name] !== "") {
var value = options.filters[$(elem).attr("name")]
if ($(elem).is(":checkbox") || $(elem).is(":radio")) {
$("input[name='" + name + "'][value='" + value + "']").prop("checked", true)
} else if ($(elem).is("select")) {
$("select[name='" + name + "'] option").each(function () {
if ($(this).val() == value) {
$(this).prop('selected', true)
}
}, value)
} else {
$(elem).val(value)

if (!this.skipLoadFilterFromLocalStorage) {
$("form[name='" + this.getFormName() + "'] [name]").each(function (index, elem) {
let name = $(elem).attr("name");
let value = options.filters[name];

if (value === ""){
return;
}
}
})

let multiple = $(elem).attr('multiple');
switch (true){
case $(elem).is(":checkbox"):
case $(elem).is(":radio"):
$("input[name='" + name + "'][value='" + value + "']").prop("checked", true);
break;
case $(elem).is("select") && !multiple:
$("select[name='" + name + "'] option[value='"+value+"']").prop('selected', true);
break;
case $(elem).is("select") && multiple:
value.forEach((val) => {
$("select[name='" + name + "'] option[value='"+val+"']").prop('selected', true);
});
break;
default:
$(elem).val(value);
break;
}
});
}

if (typeof options.hiddenColumns === "undefined") {
this.hiddenColumns = [];
Expand Down

0 comments on commit b6f0507

Please sign in to comment.