Skip to content

Commit

Permalink
fix(form): multiple selects return arrays for dirtycheck
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
lubber-de authored Jul 31, 2020
1 parent 33397cc commit 182dd81
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/definitions/behaviors/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -366,9 +366,15 @@ $.fn.form = function(parameters) {
var initialValue = $el.data(metadata.defaultValue);
// Explicitly check for null/undefined here as value may be `false`, so ($el.data(dataInitialValue) || '') would not work
if (initialValue == null) { initialValue = ''; }
else if(Array.isArray(initialValue)) {
initialValue = initialValue.toString();
}
var currentValue = $el.val();
if (currentValue == null) { currentValue = ''; }

// multiple select values are returned as arrays which are never equal, so do string conversion first
else if(Array.isArray(currentValue)) {
currentValue = currentValue.toString();
}
// Boolean values can be encoded as "true/false" or "True/False" depending on underlying frameworks so we need a case insensitive comparison
var boolRegex = /^(true|false)$/i;
var isBoolValue = boolRegex.test(initialValue) && boolRegex.test(currentValue);
Expand Down

0 comments on commit 182dd81

Please sign in to comment.