Skip to content

Commit cde467a

Browse files
committed
netteForms.js: fixed getValue for multi select box
1 parent 800df9b commit cde467a

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/assets/netteForms.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,6 @@ Nette.getValue = function(elem) {
6666
} else if (elem.type === 'file') {
6767
return elem.files || elem.value;
6868

69-
} else if (elem.name.match(/\[\]$/)) { // multi element with single option
70-
return Nette.getValue([elem]);
71-
7269
} else if (elem.tagName.toLowerCase() === 'select') {
7370
var index = elem.selectedIndex,
7471
options = elem.options,
@@ -85,6 +82,9 @@ Nette.getValue = function(elem) {
8582
}
8683
return values;
8784

85+
} else if (elem.name && elem.name.match(/\[\]$/)) { // multi element with single option
86+
return Nette.getValue([elem]);
87+
8888
} else if (elem.type === 'checkbox') {
8989
return elem.checked;
9090

tests/netteForms/spec/Nette.validateRuleSpec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,15 +285,15 @@ describe('Nette.getValue & validateRule', function() {
285285

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

294294
var doc = fixtures.window().document,
295295
form = doc.forms[0],
296-
el = form.input;
296+
el = form['input[]'];
297297

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

0 commit comments

Comments
 (0)