LCweb-ita / LC-switch

Superlight vanilla javascript plugin improving forms look and functionality

Home Page:https://lcweb.it/lc-switch-javascript-plugin

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Feature Request: make events bubbling or dispatch a bubbling change event on toggle

clst opened this issue · comments

commented

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).

commented

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

commented

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.
b153ae2

commented

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.

commented

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.