MDL-60012 form: fix 'neq' disabledif regression

This commit is contained in:
Davo Smith 2017-09-14 16:28:53 +01:00
parent 32f9550e85
commit 8cab0a2571

View File

@ -62,16 +62,19 @@ if (typeof M.form.dependencyManager === 'undefined') {
* Initializes the mapping from element name to YUI NodeList
*/
initElementsByName: function() {
var names = {};
var names = {}; // Form elements with a given name.
var allnames = {}; // Form elements AND outer elements for groups with a given name.
// Collect element names.
Y.Object.each(this.get('dependencies'), function(conditions, i) {
names[i] = new Y.NodeList();
allnames[i] = new Y.NodeList();
for (var condition in conditions) {
for (var value in conditions[condition]) {
for (var hide in conditions[condition][value]) {
for (var ei in conditions[condition][value][hide]) {
names[conditions[condition][value][hide][ei]] = new Y.NodeList();
allnames[conditions[condition][value][hide][ei]] = new Y.NodeList();
}
}
}
@ -83,16 +86,17 @@ if (typeof M.form.dependencyManager === 'undefined') {
var name = node.getAttribute('name');
if (({}).hasOwnProperty.call(names, name)) {
names[name].push(node);
allnames[name].push(node);
}
});
// Locate any groups with the given name.
this.get('form').all('.fitem').each(function(node) {
var name = node.getData('groupname');
if (name && ({}).hasOwnProperty.call(names, name)) {
names[name].push(node);
if (name && ({}).hasOwnProperty.call(allnames, name)) {
allnames[name].push(node);
}
});
this._nameCollections = names;
this._nameCollections = [names, allnames];
},
/**
@ -100,16 +104,22 @@ if (typeof M.form.dependencyManager === 'undefined') {
* a YUI NodeList
*
* @param {String} name The form element name.
* @param {Boolean} includeGroups (optional - default false) Should the outer element for groups be included?
* @return {Y.NodeList}
*/
elementsByName: function(name) {
elementsByName: function(name, includeGroups) {
if (includeGroups === undefined) {
includeGroups = false;
}
var collection = (includeGroups ? 1 : 0);
if (!this._nameCollections) {
this.initElementsByName();
}
if (!({}).hasOwnProperty.call(this._nameCollections, name)) {
if (!({}).hasOwnProperty.call(this._nameCollections[collection], name)) {
return new Y.NodeList();
}
return this._nameCollections[name];
return this._nameCollections[collection][name];
},
/**
@ -269,7 +279,7 @@ if (typeof M.form.dependencyManager === 'undefined') {
* @param {Boolean} hidden True to hide, false to show.
*/
_hideElement: function(name, hidden) {
var els = this.elementsByName(name);
var els = this.elementsByName(name, true);
els.each(function(node) {
var e = node.ancestor('.fitem', true);
if (e) {