Disabling checkboxes when one is already selected...

3,852 views
Skip to first unread message

telagraphic

unread,
Jan 20, 2014, 5:19:48 PM1/20/14
to ang...@googlegroups.com
In a ng-repeat collection, when a record has its checkbox selected I want to disable all the other records checkboxes.

With my current code, that works but you can still checkbox the disabled checkbox.  Very strange...

Steve Lorimer

unread,
Jan 21, 2014, 12:43:17 AM1/21/14
to ang...@googlegroups.com
I think you're missing some files in your plunker. (services & filters)

telagraphic

unread,
Jan 21, 2014, 12:31:55 PM1/21/14
to ang...@googlegroups.com
I tried updating the plunker with those files, but it is still erroring and I can't tell what the error is!

Here is a gist that simplifies what I'm trying to do.  

When a checkbox is checked true, then I want the other checkboxes in the list to disable.  When the checked checkbox is unchecked, they should be enabled again.

What is the best way to do this besides using a directive to query the dom and change styles, which is how my directive is attempting to do.

Not sure how to call ng-show or ng-disabled from a directive for the other elements.

The code in my directive is complaining that my element doesn't have a hasClass method for it.  Not sure how to debug this...

telagraphic

unread,
Jan 21, 2014, 12:32:41 PM1/21/14
to ang...@googlegroups.com

Steve Lorimer

unread,
Jan 21, 2014, 5:27:51 PM1/21/14
to ang...@googlegroups.com
Your plunker is still missing half your code and the gist is just a cut and paste of some parts of the code in your original plunker.

I'm sure you'll get a lot more help if you take the effort to create a working example. 

All that said, all you need to do is save the current winner's id in the parent scope. Then in your ng-repeat, you set your checkbox's ng-disabled to be false if either there is a current winner id in the parent scope, or the current winner id === the current bet id

Steve Lorimer

unread,
Jan 22, 2014, 10:19:37 PM1/22/14
to ang...@googlegroups.com
I had a thought... is it possible you're trying to duplicate the functionality of radio buttons?

Steve Lorimer

unread,
Jan 22, 2014, 10:36:36 PM1/22/14
to ang...@googlegroups.com

Dawen

unread,
Mar 19, 2014, 2:13:32 AM3/19/14
to ang...@googlegroups.com, steve....@gmail.com
I had the same thought at first.  However, there is a scenario where one checking one checkbox disables the rest of them.  On a Profile Settings or Email Subscription page, clicking on "Subscribe to All" will enable or disable all checkboxes.
Reply all
Reply to author
Forward
0 new messages