Skip to content

Commit

Permalink
netteForms.js: fixed bug in toggleControl, episode II. [Closes #67]
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Feb 20, 2015
1 parent c3006dc commit 8a7bedf
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions src/assets/netteForms.js
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,8 @@ Nette.toggleControl = function(elem, rules, success, firsttime, value) {
handled = [],
handler = function () {
Nette.toggleForm(elem.form, elem);
};
},
curSuccess;

for (var id = 0, len = rules.length; id < len; id++) {
var rule = rules[id],
Expand All @@ -431,20 +432,24 @@ Nette.toggleControl = function(elem, rules, success, firsttime, value) {
continue;
}

curSuccess = success;
if (success !== false) {
rule.neg = op[1];
rule.op = op[2];
var curValue = elem === curElem ? value : {value: Nette.getEffectiveValue(curElem)},
res = Nette.validateRule(curElem, rule.op, rule.arg, curValue);
if (res === null) {
var curValue = elem === curElem ? value : {value: Nette.getEffectiveValue(curElem)};
curSuccess = Nette.validateRule(curElem, rule.op, rule.arg, curValue);
if (curSuccess === null) {
continue;

} else if (!rule.rules) {
success = rule.neg ? !res : res;
} else if (rule.neg) {
curSuccess = !curSuccess;
}
if (!rule.rules) {
success = curSuccess;
}
}

if ((rule.rules && Nette.toggleControl(elem, rule.rules, success, firsttime, value)) || rule.toggle) {
if ((rule.rules && Nette.toggleControl(elem, rule.rules, curSuccess, firsttime, value)) || rule.toggle) {
has = true;
if (firsttime) {
var oldIE = !document.addEventListener, // IE < 9
Expand All @@ -459,7 +464,7 @@ Nette.toggleControl = function(elem, rules, success, firsttime, value) {
}
for (var id2 in rule.toggle || []) {
if (Object.prototype.hasOwnProperty.call(rule.toggle, id2)) {
Nette.toggles[id2] = Nette.toggles[id2] || (rule.toggle[id2] ? success : !success);
Nette.toggles[id2] = Nette.toggles[id2] || (rule.toggle[id2] ? curSuccess : !curSuccess);
}
}
}
Expand Down

0 comments on commit 8a7bedf

Please sign in to comment.