-
Notifications
You must be signed in to change notification settings - Fork 101
Implements two public methods: toggle allows toggling the button via js. #9
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
base: master
Are you sure you want to change the base?
Conversation
…ilentToggle does the same only without triggering a change event.
Added a third 'redraw' method that brings the button back in sync with the checkbox. |
@ErwinM, I'm a total newbie. Can you tell me how to trigger the 'redraw' method? What do I call after this? $("#switch1 input").prop('checked', true); |
@ErwinM thanks for your PR, however I wonder if this is really the way to go? Shouldn't we listen to the change event of the underlying checkbox and silently update the switch button when the checkbox state changes? |
$("#switch1 input").switchButton("redraw"); You'll have to check out @ErwinM's code though |
Yup, I've tried that: $("#switch1 input").switchButton("redraw"); I keep getting: Uncaught TypeError: Object [object Object] has no method 'switchButton' The selector is definitely returning something, and I do this to turn the checkbox into the switchButton (which works fine):
One of these days I'll figure out this whole jQuery/Javascript world. Cool widget though. |
@mikem1977 Are you sure you checked out my fork of SwitchButton from my Github repo? @olance I agree what you propose is nicer. However, this suited my needs and I thought perhaps it would help other. There is no harm in having a redraw method? Up to you of course. |
@ErwinM, I got it to work. I had to do something like: """ function init_switches() { function update_switch_state() { """ I'm quite the JQuery/Javascript newbie, so I can't really understand/explain why using a variable works instead of the selector. |
SilentToggle does the same only without triggering a change event. This solves #7.