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

Radio button true and false value bug #68

Open
andrewchernow opened this issue Aug 13, 2014 · 1 comment
Open

Radio button true and false value bug #68

andrewchernow opened this issue Aug 13, 2014 · 1 comment

Comments

@andrewchernow
Copy link

When a group of radios uses "true" or "false" for their values, form2js converts these to boolean true and false. However, if you add a 3rd radio to the group to indicate "none selected" or "no answer" or "any" and set its value to "", form2js will convert the checked radio with a value of "" to boolean false. However, if you don't use "true" and "false" as the values, the "" value works as expected.

This is because of the radio case in getFieldValue, which falls-through to the checkbox case. The offending line from the checkbox case is:

if(!fieldNode.checked && fieldNode.value === "true") return false;

This is correct for checkboxes, but for something like:

any
on
off

It is broken. I should not get back boolean false if the "any" radio is checked. I should get back "". To fix this, i just copied the statements from the checkbox case in getFieldValue, excluding the offending line, to the radio case.

Point is, this feels like a bug or maybe just unexpected behavior. IMHO, getFieldValue should not treat a radio just like a checkbox.

@andrewchernow
Copy link
Author

Sorry, I didn't format the radio group.

<input type="radio" name="state" value="" checked="checked" />any
<input type="radio" name="state" value="true" />on
<input type="radio" name="state" value="false" " />off

The above produces:

{"state": false}

What I would expect and what the change I made produces is:

{"state": ""}

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

No branches or pull requests

1 participant