Running into a case where values are being set when the record is invalid which causes problems for multiple inputs that have the same name/id. I would suggest that no values are set unless the full record is valid. Any further thoughts on this?
Example Problem
I've got a form with a table that has rows that can be checked e.g.:
| Option |
Use |
| Foo |
[ ] |
| Bar |
[ ] |
| Baz |
[ ] |
Each of the checkboxes has the same name and id but different values e.g:
<input type="checkbox" id="option_ids" value="foo">
<input type="checkbox" id="option_ids" value="bar">
<input type="checkbox" id="option_ids" value="baz">
When there are multiple inputs with the same id then dbForm condenses the values into an array for form submission. If there are any other invalid fields in the submission then the JSON response will mirror this array:
{
"status": "invalid",
"record": {
"ref": {
"valid": false,
"message": "Invalid reference.",
"value": ""
},
"option_ids": {
"valid": true,
"message": "",
"value": "foo bar baz"
},
...
}
}
dbForm will then parse the JSON and set the first element with a matching id to the value provided. This means that my checkbox values change to:
<input type="checkbox" id="option_ids" value="foo bar baz">
<input type="checkbox" id="option_ids" value="bar">
<input type="checkbox" id="option_ids" value="baz">
The value for the first checkbox isn't correct and therefore will cause problems. If the values were only updated when the full submission was valid then it could avoid problems like this.
Running into a case where values are being set when the record is invalid which causes problems for multiple inputs that have the same name/id. I would suggest that no values are set unless the full record is valid. Any further thoughts on this?
Example Problem
I've got a form with a table that has rows that can be checked e.g.:
Each of the checkboxes has the same name and id but different values e.g:
<input type="checkbox" id="option_ids" value="foo"><input type="checkbox" id="option_ids" value="bar"><input type="checkbox" id="option_ids" value="baz">When there are multiple inputs with the same id then dbForm condenses the values into an array for form submission. If there are any other invalid fields in the submission then the JSON response will mirror this array:
{ "status": "invalid", "record": { "ref": { "valid": false, "message": "Invalid reference.", "value": "" }, "option_ids": { "valid": true, "message": "", "value": "foo bar baz" }, ... } }dbForm will then parse the JSON and set the first element with a matching id to the value provided. This means that my checkbox values change to:
<input type="checkbox" id="option_ids" value="foo bar baz"><input type="checkbox" id="option_ids" value="bar"><input type="checkbox" id="option_ids" value="baz">The value for the first checkbox isn't correct and therefore will cause problems. If the values were only updated when the full submission was valid then it could avoid problems like this.