From ecfce9f20747fe6077d8215509a70ee7fc9480aa 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 | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/core/misc/states.js b/core/misc/states.js index 24374b6..7903757 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 @@ -156,6 +173,10 @@ // Make sure the event we just bound ourselves to is actually fired. new states.Trigger({selector: selector, state: state}); + + // Reevaluate conditions and trigger to be sure default value like + // null is handled. + this.reevaluate(); } } }, -- 2.8.1