Commit 70f2248e 70f2248e0904af39c2e3302c3338379e4d3c14e1 by Luke Rodgers

Bugfix: `getFormValues` choked on some radio inputs.

clientutils `getMultipleValues` choked on radio inputs where any radio
before the last one was chosen, mistakenly resetting the value to
`undefined`. Added spec to cover this case.
1 parent 0d50d4fb
......@@ -478,7 +478,7 @@
if (type === 'radio') {
var value;
[].forEach.call(inputs, function(radio) {
value = radio.checked ? radio.value : undefined;
value = radio.checked ? radio.value : value;
});
return value;
} else if (type === 'checkbox') {
......
......@@ -92,7 +92,7 @@ casper.test.begin('field array', 1, function(test) {
});
});
casper.test.begin('getFormValues() tests', 1, function(test) {
casper.test.begin('getFormValues() tests', 2, function(test) {
casper.start('tests/site/form.html', function() {
this.fill('form[action="result.html"]', {
email: 'chuck@norris.com',
......@@ -118,6 +118,31 @@ casper.test.begin('getFormValues() tests', 1, function(test) {
"topic": "bar"
}, 'Casper.getFormValues() retrieves filled values');
});
casper.then(function() {
this.fill('form[action="result.html"]', {
email: 'chuck@norris.com',
password: 'chuck',
content: 'Am watching thou',
check: true,
choice: 'yes',
topic: 'bar',
file: phantom.libraryPath + '/README.md',
'checklist[]': ['1', '3']
});
});
casper.then(function() {
test.assertEquals(this.getFormValues('form'), {
"check": true,
"checklist[]": ["1", "3"],
"choice": "yes",
"content": "Am watching thou",
"email": "chuck@norris.com",
"file": "C:\\fakepath\\README.md",
"password": "chuck",
"submit": "submit",
"topic": "bar"
}, 'Casper.getFormValues() correctly retrieves values from radio inputs regardless of order');
});
casper.run(function() {
test.done();
});
......