LC-switch
LC-switch copied to clipboard
Feature Request: make events bubbling or dispatch a bubbling change event on toggle
That way code that listens on document does not need to be changed after converting a checkbox to a switch.
jQuery example: $(document).on("change lcs-statuschange", 'input' ...
does not trigger (except when clicking on the <label for="input_id">, because browser does that).
Hello. The DOM necessarily needs to be changed since inputs must be wrapped with the switch code. However in v2 I use
el.parentNode.insertBefore(wrapper, el)
(line 198)
Then attached listeners should still work. Sincerely don't know other ways to achieve it differently
Yeah I am using v2 (pretty neat, btw). The change event didn't trigger anymore after lc_switch loaded. I changed your custom event then it works with the listener above even after replacing the DOM with new inputs later. https://github.com/LCweb-ita/LC-switch/commit/b153ae226b24600770bb6220747f3223be5c14a6
Thanks for the clarification, however $(document).on("change lcs-statuschange", 'input' ... works if you place it in the demo.html file. Before and after the plugin initialization.
The "lcs-statuschange" event is correctly handled.
Yes it works fine, until you do something like $("input-container").html(newstuff); Then it needs bubbles: true.
At least it did in my case. I can check it again outside of my site, to be sure. Thanks for the quick reply and the great switch.