event handling issue for fields added post page load #88
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi Jules, hope this PR finds you well.
I have encountered 2 issues with a recent development on my Smart Grid-layout plugin which uses the HybridDropdown js plugin to display dynamic lists of checkboxes.
1. Event fired by fields added post page load not picked up.
The HybridDropdown is built and initialised from a JSON object once the document is ready, creating a list of checkbox in an HTML dropdown field. As a result, your front-end script's input change event handler,
fails to pik up the list of checkboxes as it has yet to be instantiated when your script binds events to the input fields.
I therefore suggest the following change which works just as well,
bind the event listener on the form and use event delegation to filter them. This has the advantage of binding fewer event listeners (more efficient) but also catching events fired by fields which were added post page load.
2. clear_on_hide not working for pure js event listeners
The 2nd issue is again related to the HybridDropdown field which implement a pure js event listening functionality to change the field when an external/programmatic 'change' event is fired on one of its checkbox fields.
Your front-end scripts uses the jQuery trigger method to fire a change event,
Unfortunately the trigger method has a downside that the event fired on a checkbox does not bubble up, see this StackOverflow answer for more details. I therefore propose to use the js dispatchEvent method to fire the event,
what do you think?