Skip to content

Commit 182dd81

Browse files
authored
fix(form): multiple selects return arrays for dirtycheck
The fieldDirty check failed whenever a dropdown, converted from a select tag, was part of the form and was defined as multiple The comparison of currentValue and initialValue failed for those dropdowns, because the .val() method returned arrays instead of strings for select-multiple fields. Dropdowns made out of div were working, because those use an input field, which holds a string. Raw == comparisons of two arrays are never true, so that fiel was always considered dirty.
1 parent 33397cc commit 182dd81

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/definitions/behaviors/form.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,9 +366,15 @@ $.fn.form = function(parameters) {
366366
var initialValue = $el.data(metadata.defaultValue);
367367
// Explicitly check for null/undefined here as value may be `false`, so ($el.data(dataInitialValue) || '') would not work
368368
if (initialValue == null) { initialValue = ''; }
369+
else if(Array.isArray(initialValue)) {
370+
initialValue = initialValue.toString();
371+
}
369372
var currentValue = $el.val();
370373
if (currentValue == null) { currentValue = ''; }
371-
374+
// multiple select values are returned as arrays which are never equal, so do string conversion first
375+
else if(Array.isArray(currentValue)) {
376+
currentValue = currentValue.toString();
377+
}
372378
// Boolean values can be encoded as "true/false" or "True/False" depending on underlying frameworks so we need a case insensitive comparison
373379
var boolRegex = /^(true|false)$/i;
374380
var isBoolValue = boolRegex.test(initialValue) && boolRegex.test(currentValue);

0 commit comments

Comments
 (0)