-
Notifications
You must be signed in to change notification settings - Fork 158
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
ModelBinder incorrectly handles true/false radio button values #165
Comments
@elwayman02 - this is strange. I just ran a quick test and things appear to be working fine... Here are some snippets from my quick test - have you tried with the latest?
|
I tried it on Chrome w/ jQuery 1.10.2 and ModelBinder 1.0.5, so I'm not sure how it worked for you. I had to write the following custom converter to get it to work. converter: function(direction, value) {
if (_.isEqual(direction, ModelBinder.Constants.ViewToModel)) {
return value === "true";
} else if (value === true) {
return "true";
} else if (value === false) {
return 'false';
}
return '';
} |
I'll leave this issue open. If anyone else has the same issue I'll introduce the change to the Backbone.ModelBinder. Sorry - I just can't replicate the issue. |
I'm having this problem as well. Backbone 1.1, ModelBinder 1.0.5. Without a converter, no radio button is selected. converter: (dir, value) -> "" + value |
I just experienced the same problem. I used thrar's solution to overcome it. I'm using ModelBinder 1.0.5 and Backbone 1.1.2. |
Checkboxes bind fine to a boolean model attribute but radio buttons do not. They seem to set the value attribute as string and are not checked when model value is set true. |
I have face the same issue, because I had given checked attribute to a radio button in group to make it checked by default. |
I found that, if your model returns and integer value, which is used to populate the radio buttons value the ModelBinding does not select the radio button value. Providing a converter like
seemed to work for me |
The way to get Boolean "value" settings to work, is to "v-bind" to the value so that Vue treats it as a JavaScript expression rather than a string. As mentioned at the "Passing a Number" section of the guide:
|
I think you might be posting in the wrong thread @mgrollins... |
Mr Trolling ? ;-) |
ModelBinder is unable to correctly check a radio button if its value is a boolean.
The problem manifests on line 397 of ModelBinder.js:
Let's say the element looks like this:
el.val() returns "true" as a string, but the value on the model is an actual boolean (because that's how the data is truly represented). So "true" === true evaluates to false and the radio button is not checked.
I could write a converter to force the value to be converted to a string (which I'm going to have to do in the meantime), but I think the proper solution would be to have ModelBinder check to see if convertedValue is a boolean and convert it to a string in the case of a radio button.
Something like this:
The text was updated successfully, but these errors were encountered: