Radio Button toggling other fields being enabled or disabled

6,351 views
Skip to first unread message

Andrew Luly

unread,
May 23, 2013, 4:05:30 PM5/23/13
to ang...@googlegroups.com
Hello all, I have a project I'm working on where I have X number of radio buttons, and pending which one is selected I want to disable other sections, however it doesn't seem to work.  Any help would be greatly appreciated, here is my code broken using radio buttons:
http://jsfiddle.net/whomba/DGUUn/

and here it is working using check boxes:

Note the 'ng-checked' vs 'ng-model' difference on the 2 inputs at the top, only that and the type were changed.

Any help would be much appreciated.

Raymond Z.

unread,
May 23, 2013, 6:51:06 PM5/23/13
to ang...@googlegroups.com
ng-checked creates a one-way data binding, so the model does not get updated when you toggle the radio buttons.

If you're using radio buttons, you still need to use ng-model:

<input type="radio" ng-model="selection" value="0"/>
<input type="radio" ng-model="selection" value="1"/>
<input type="radio" ng-model="selection" value="2"/>

When the user selects a radio button, the model is set to the button's value.


(I've added some application logic to the controller to query which radio button is selected. This is used for the ng-disabled check.)

Andrew Luly

unread,
May 24, 2013, 9:34:25 AM5/24/13
to ang...@googlegroups.com
Thanks Raymond, I did end up using something like that, however needing to compare things like that seemed somewhat 'anti angular' and cumbersome in solution, thus I thought I was doing it wrong.

Thank you for the speedy response!


--
You received this message because you are subscribed to a topic in the Google Groups "AngularJS" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/angular/u6aVzkkRJnk/unsubscribe?hl=en-US.
To unsubscribe from this group and all its topics, send an email to angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular?hl=en-US.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
Andrew Luly
(513) 494-6622

"When you do things rightpeople won't be sure you've done anything at all."
Reply all
Reply to author
Forward
0 new messages