Commit 416751ab 416751abb2e9be9477f50c172bb138e6a78735f1 by Nicolas Perriault

Merge pull request #375 from lukeasrodgers/bugfix_getFormValues

Bugfix get form values
2 parents 6541ac75 70f2248e
......@@ -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') {
......@@ -511,7 +511,7 @@
var self = this;
[].forEach.call(form.elements, function(element) {
var name = element.getAttribute('name');
if (name) {
if (name && !values[name]) {
values[name] = self.getFieldValue(name);
}
});
......
......@@ -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();
});
......