fix saving multiple selects as json arrays

v1.18.x
Barış Soner Uşaklı 7 years ago
parent c6c31e9e5f
commit a4c24cb66b

@ -457,6 +457,18 @@ define('settings', function () {
return callback(err);
}
// multipe selects are saved as json arrays, parse them here
$(formEl).find('select[multiple]').each(function (idx, selectEl) {
var key = $(selectEl).attr('name');
if (key && values.hasOwnProperty(key)) {
try {
values[key] = JSON.parse(values[key]);
} catch (e) {
// Leave the value as is
}
}
});
// Save loaded settings into ajaxify.data for use client-side
ajaxify.data.settings = values;
@ -479,6 +491,7 @@ define('settings', function () {
formEl = $(formEl);
if (formEl.length) {
var values = formEl.serializeObject();
// "Fix" checkbox values, so that unchecked options are not omitted
formEl.find('input[type="checkbox"]').each(function (idx, inputEl) {
inputEl = $(inputEl);
@ -487,6 +500,12 @@ define('settings', function () {
}
});
// save multiple selects as json arrays
formEl.find('select[multiple]').each(function (idx, selectEl) {
selectEl = $(selectEl);
values[selectEl.attr('name')] = JSON.stringify(selectEl.val());
});
socket.emit('admin.settings.set', {
hash: hash,
values: values,

Loading…
Cancel
Save