fix: [settings] Correctly detect value changes for select[multiple]

pull/73/head
Sami Mokaddem 2021-10-20 13:16:03 +02:00
parent 6c4efc044d
commit 64fdd4d290
No known key found for this signature in database
GPG Key ID: 164C473F627A06FA
2 changed files with 14 additions and 1 deletions

View File

@ -52,6 +52,9 @@ $(document).ready(function () {
oldValue = oldValue !== undefined ? oldValue : ''
}
$input.val(oldValue)
if ($input.is('select') && $input.prop('multiple')) {
$input.trigger('change')
}
handleSettingValueChange($input)
})
@ -85,7 +88,11 @@ function handleSettingValueChange($input) {
if ($input.attr('type') == 'checkbox') {
oldValue = oldValue == true
}
if (newValue == oldValue || (newValue == '' && oldValue == undefined)) {
let hasChanged = newValue != oldValue
if ($input.is('select') && $input.prop('multiple')) {
hasChanged = !arrayEqual(oldValue, newValue)
}
if (!hasChanged || (newValue == '' && oldValue == undefined)) {
restoreWarnings($input)
} else {
removeWarnings($input)

View File

@ -145,4 +145,10 @@ function debounce(func, wait, options) {
debounced.flush = flush
debounced.pending = pending
return debounced
}
function arrayEqual(array1, array2) {
const array2Sorted = array2.slice().sort();
return array1.length === array2.length && array1.slice().sort().every((value, index) => value === array2Sorted[index])
}