Issue
I have a form with three radio buttons, and deferred binding to model on click of submit. Live example here
This works perfectly fine in the happy path scenario:
- Select
radio1
> clicksubmit
givesradio1
as the result.
But in the following scenario it breaks:
- Select radio1 > click submit > gives
radio1
- Now select
radio2
> thenradio3
> and then clicksubmit
. - This gives
radio2
instead ofradio3
as the bound value.
Basically, if I make multiple changes to the radio group, only the first change gets captured. How can I change this behaviour to reflect the last change instead?
Solution
You have to use allowInvalid : true in ngModelOptions to validate correctly instead of the default behavior of setting the model to undefined. See documentation.
<input type="radio" name="radio" value="radio1" ng-model="radioValue" ng-model-options="{updateOn: 'submit', allowInvalid : true}" >
<input type="radio" name="radio" value="radio2" ng-model="radioValue" ng-model-options="{updateOn: 'submit', allowInvalid : true}">
<input type="radio" name="radio" value="radio3" ng-model="radioValue" ng-model-options="{updateOn: 'submit', allowInvalid : true}">
Working Plunker Link
Answered By - Fracedo
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.