Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dbForm (xml|json)SetValues – Should dbForm set any values if the record is invalid? #167

Open
nicky-johnstone opened this issue Sep 18, 2017 · 0 comments
Labels

Comments

@nicky-johnstone
Copy link
Member

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:

  1. <input type="checkbox" id="option_ids" value="foo">
  2. <input type="checkbox" id="option_ids" value="bar">
  3. <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:

  1. <input type="checkbox" id="option_ids" value="foo bar baz">
  2. <input type="checkbox" id="option_ids" value="bar">
  3. <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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant