From bb1da7935abe33f0e9749aed49686acf9eff4aad Mon Sep 17 00:00:00 2001 From: GoZ Date: Thu, 19 Jan 2017 09:17:07 +0100 Subject: [PATCH] Issue #1149078 by wuinfo, peterpoe, legolasbo, mgifford, jrb, himanshupathak3, arcaneadam, Kuntyi, nod_: States API doesn't work with multiple select fields --- core/misc/states.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/core/misc/states.js b/core/misc/states.js index 24374b6..88adc0c 100644 --- a/core/misc/states.js +++ b/core/misc/states.js @@ -103,6 +103,23 @@ // The "reference" variable is a comparison function. return reference(value); }, + Array: function (reference, value) { + // Make sure value is an array. + if (!Array.isArray(value)) { + return false; + } + // Convert all comparisons to strings for indexOf to work with integers comparing to strings + reference = reference.map(String); + value = value.map(String); + // We iterate through each value provided in the reference. If all of them + // exist in value array, we return true. Otherwise return false. + for (var key in reference) { + if (reference.hasOwnProperty(key) && value.indexOf(reference[key]) === -1) { + return false; + } + } + return true; + }, Number: function (reference, value) { // If "reference" is a number and "value" is a string, then cast // reference as a string before applying the strict comparison in @@ -201,7 +218,7 @@ */ update: function (selector, state, value) { // Only act when the 'new' value is actually new. - if (value !== this.values[selector][state.name]) { + if (value !== this.values[selector][state.name] || $(selector).prop('multiple')) { this.values[selector][state.name] = value; this.reevaluate(); } -- 2.8.1