SebastianP Posted February 12, 2020 Share Posted February 12, 2020 Hi, is there a way to run a javascript function after add a new repeater item? I want to register an event handler on a page reference field inside the repeater item. I have inserted a custom javascript file with a runtimemarkup field. Thank you for any suggestions! Regards Sebastian Link to comment Share on other sites More sharing options...
bernhard Posted February 12, 2020 Share Posted February 12, 2020 $(document).on('repeateradd', function() { alert('added'); }); https://github.com/processwire/processwire/blob/master/wire/modules/Fieldtype/FieldtypeRepeater/InputfieldRepeater.js#L330 4 Link to comment Share on other sites More sharing options...
Robin S Posted February 12, 2020 Share Posted February 12, 2020 2 hours ago, SebastianP said: I want to register an event handler on a page reference field inside the repeater item. Is the event handler specific to the page reference field inside only new repeater items, or should it handle events of the page reference field inside all repeater items? Because if it's the latter you probably don't need to do anything in particular when a new repeater item is added - rather you can attach the handler to "document" and then use a selector to filter descendants. So supposing your handler is for the "change" event of selects named "foo" inside repeater items... $(document).on('change', 'select[name^=foo_repeater]', function() { console.log('repeater select changed'); }); Edit: and if only inside new repeater items then this seems to do the job: $(document).on('change', '.InputfieldRepeaterItemRequested select[name^=foo_repeater]', function() { console.log('new repeater item select changed'); }); 3 Link to comment Share on other sites More sharing options...
SebastianP Posted February 13, 2020 Author Share Posted February 13, 2020 Hi Bernhard, hi Robin S, thank you! That is what I was looking for. Regards Sebastian Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now