Skip to content

Commit

Permalink
netteForms.js: fixed length validation on checkbox list with exactly …
Browse files Browse the repository at this point in the history
…1 item [Closes #59]
  • Loading branch information
dg committed Feb 8, 2015
1 parent 4917e9c commit 22d3d82
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
11 changes: 6 additions & 5 deletions src/assets/netteForms.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,8 @@ Nette.getValue = function(elem) {
}
return values;

} else if (elem.type === 'checkbox') {
return elem.checked;

} else if (elem.type === 'radio') {
return elem.checked && elem.value;
} else if (elem.type === 'checkbox' || elem.type === 'radio') {
return Nette.getValue([elem]);

} else if (elem.type === 'file') {
return elem.files || elem.value;
Expand Down Expand Up @@ -259,7 +256,11 @@ Nette.validators = {
equal: function(elem, arg, val) {
if (arg === undefined) {
return null;

} else if (elem.type === 'checkbox' && arg === true && val) {
return true;
}

val = Nette.isArray(val) ? val : [val];
arg = Nette.isArray(arg) ? arg : [arg];
loop:
Expand Down
6 changes: 3 additions & 3 deletions tests/netteForms.js/spec/Nette.validateRuleSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,13 @@ describe('Nette.getValue & validateRule', function() {
form = doc.forms[0],
el = form.input;

expect(Nette.getValue(el)).toBe(false);
expect(Nette.getValue(el)).toBe(null);
expect(Nette.validateRule(el, 'filled')).toBe(false);
expect(Nette.validateRule(el, 'blank')).toBe(true);
expect(Nette.validateRule(el, 'equal', false)).toBe(true);

el.checked = true;
expect(Nette.getValue(el)).toBe(true);
expect(Nette.getValue(el)).toBe('r');
expect(Nette.validateRule(el, 'filled')).toBe(true);
expect(Nette.validateRule(el, 'blank')).toBe(false);
expect(Nette.validateRule(el, 'equal', true)).toBe(true);
Expand Down Expand Up @@ -165,7 +165,7 @@ describe('Nette.getValue & validateRule', function() {
form = doc.forms[0],
el = form.input;

expect(Nette.getValue(el)).toBe(false);
expect(Nette.getValue(el)).toBe(null);
expect(Nette.validateRule(el, 'filled')).toBe(false);
expect(Nette.validateRule(el, 'blank')).toBe(true);
expect(Nette.validateRule(el, 'equal', ['f', 'm'])).toBe(false);
Expand Down

0 comments on commit 22d3d82

Please sign in to comment.