Skip to content

Commit

Permalink
netteForms.js: fixed getValue for multi select box
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed May 4, 2015
1 parent 800df9b commit cde467a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/assets/netteForms.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,6 @@ Nette.getValue = function(elem) {
} else if (elem.type === 'file') {
return elem.files || elem.value;

} else if (elem.name.match(/\[\]$/)) { // multi element with single option
return Nette.getValue([elem]);

} else if (elem.tagName.toLowerCase() === 'select') {
var index = elem.selectedIndex,
options = elem.options,
Expand All @@ -85,6 +82,9 @@ Nette.getValue = function(elem) {
}
return values;

} else if (elem.name && elem.name.match(/\[\]$/)) { // multi element with single option
return Nette.getValue([elem]);

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

Expand Down
4 changes: 2 additions & 2 deletions tests/netteForms/spec/Nette.validateRuleSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,15 +285,15 @@ describe('Nette.getValue & validateRule', function() {

it('multi selectbox', function() {
fixtures.set('<form> \
<select name="input" multiple> \
<select name="input[]" multiple> \
<optgroup label="World"><option value="bu" id="option-2">Buranda</option></optgroup> \
<option value="?" id="option-3">other</option> \
</select> \
</form>');

var doc = fixtures.window().document,
form = doc.forms[0],
el = form.input;
el = form['input[]'];

expect(Nette.getValue(el)).toEqual([]);
expect(Nette.validateRule(el, 'filled')).toBe(false);
Expand Down

0 comments on commit cde467a

Please sign in to comment.