Javascript on change event not working for delegated events
-
Ran into this on a client site where we have a form for scheduling time off. We have a datepicker field that when a date is selected it updates a select dropdown field by selecting the day of the week for that particular date. If we use a direct binding, it works fine:
jQuery('.forminator-custom-form .forminator-datepicker').on('change', function() { console.log('datepicker changed'); });However, because this is a tool to schedule time off, we needed to adapt this to use a repeater field group, and as such we changed our Javascript to use a delegated event handler:
jQuery('.forminator-custom-form').on('change', '.forminator-datepicker', function() { console.log('delegated datepicker changed'); });However this fails to fire. Something within the form’s javascript event hierarchy is consuming the change event and stopping the propagation.
I’ve set this up on a dev site where the only plugin installed is Forminator v1.48.3 running on WordPress v6.8.3. Appreciate any guidance on how we might make this work on a repeater field without having to resort to re-running our event handler attachments every time there is a click or something.
Also… it would be handy if your javascript library triggered an event when a repeater group is added or removed (eg. forminator:repeater:add, forminator:repeater:remove).
The page I need help with: [log in to see the link]
You must be logged in to reply to this topic.