You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
Repository navigation
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
Bootstrap 3 javascript checkbox and radio button toggle prevents angular's ng-model from updating on input #4516
When using Bootstrap 3's javascript buttons for checkboxes, the checkbox's ng-model does not get updated. Looking into the source code for both I know why.
The problem is Angular's checkbox is listening for the click event whereas Bootstrap's button handles the click event and fires the change event on the checkbox input.
I wrote a simple directive that does exactly what Angular's checkbox click event listener does but instead listens for the change event.
Is there a reason why Angular listens for the click event for radio and checkboxes instead of the change event? Should I create a pull request and change the click event listener to be a change event listener? This would be my first pull request.
Could you guys post a really minimal reproduction? If it's something like pointer-events: none or something then I'm not sure what we can really do about that
I see what's happening. So, I'm not sure if it would be right to handle this in angular core, this seems like it's more the domain of custom directives for interop with bootstrap. So writing your own is one thing, or otherwise hacking on n angular-strap or angular-ui/bootstrap or others.
Thanks for posting a workaround for checkboxed toggle buttons that works reasonably well. However, as one of the referenced issues suggests, it seems like the workaround as mentioned by pholly, will require two clicks for the initial toggle if the checkbox is checked by default. See http://jsfiddle.net/6admtjf1/1/ (I forked stevschmid's fiddle, added ng-checked="true" to the checkbox, and removed bootstrap css to emphasize what is going on "behind the curtain").
Any ideas how to work around the workaround, to make this work as expected even if the default state for the button is checked?
Activity
stevschmid commentedon Jan 22, 2014
I ran into the same issue.
caitp commentedon Jan 22, 2014
Could you guys post a really minimal reproduction? If it's something like
pointer-events: noneor something then I'm not sure what we can really do about thatstevschmid commentedon Jan 24, 2014
fiddle
caitp commentedon Jan 24, 2014
I see what's happening. So, I'm not sure if it would be right to handle this in angular core, this seems like it's more the domain of custom directives for interop with bootstrap. So writing your own is one thing, or otherwise hacking on n angular-strap or angular-ui/bootstrap or others.
But I'll see what people think about it
stevschmid commentedon Jan 25, 2014
Why is angular listening for
clickevents instead ofchangeevents for both radio buttons and check boxes?danse commentedon Feb 24, 2014
👍
ericpeters0n commentedon Mar 17, 2014
+1
david-hollifield commentedon Mar 26, 2014
+1
bimusiek commentedon Mar 27, 2014
👍
david-hollifield commentedon Mar 27, 2014
To anyone that's interested, pholly's directive fixed the issue I was having with my radio buttons (with a minor tweak).
fgmacedo commentedon Jun 27, 2014
+1
8 remaining items
glorat commentedon Oct 9, 2014
+1 and much gratitude for people here posting the workaround
claudijo commentedon Dec 10, 2014
Thanks for posting a workaround for checkboxed toggle buttons that works reasonably well. However, as one of the referenced issues suggests, it seems like the workaround as mentioned by pholly, will require two clicks for the initial toggle if the checkbox is checked by default. See http://jsfiddle.net/6admtjf1/1/ (I forked stevschmid's fiddle, added ng-checked="true" to the checkbox, and removed bootstrap css to emphasize what is going on "behind the curtain").
Any ideas how to work around the workaround, to make this work as expected even if the default state for the button is checked?
ppryde commentedon Feb 16, 2015
+1
heridev commentedon Oct 14, 2015
In order to support default checked checkboxes I ended up using
Is there a better way to support pre-selected checkboxes?
ERobishaw commentedon Nov 5, 2015
Just use the angular-ui button function:
http://angular-ui.github.io/bootstrap/versioned-docs/0.12.0/#/buttons
Fleisch commentedon Dec 15, 2015
+1 .... @ERobishaw thank you.. instantly worked
fix(input): listen on "change" for radio and checkbox
fix(input): listen on "change" for radio and checkbox
fix(input): listen on "change" for radio and checkbox
fix(input): listen on "change" for radio and checkbox ngModels
fix(input): listen on "change" for radio and checkbox ngModels
fix(input): listen on "change" for radio and checkbox ngModels
fix(input): listen on "change" for radio and checkbox ngModels instea…
fix(input): listen on "change" instead of "click" for radio/checkbox …