Implements two public methods: toggle allows toggling the button via js. #9
Implements two public methods: toggle allows toggling the button via js. #9ErwinM wants to merge 2 commits intoolance:masterfrom
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.