I’m using the repeater for a user-posting submission form, but want to add the code
onFocus="geolocate()"
to each instance of one of the repeating fields (so that I can tap into the Google Places API, and auto-fill addresses as the user types). So, for example,
<input type="text" id="acf-field_598a76a814237-0-field_598a771514239" class="" name="acf[field_598a76a814237][0][field_598a771514239]" value="" placeholder="" maxlength="">
would become
<input type="text" id="acf-field_598a76a814237-0-field_598a771514239" class="" name="acf[field_598a76a814237][0][field_598a771514239]" value="" placeholder="" maxlength="" onFocus="geolocate()">
Any advice on doing this? I’m using ACF Pro. Thanks!!
https://www.advancedcustomfields.com/resources/adding-custom-javascript-fields/
See the append action. You and use this action to detect what field is being added and then add additional actions to the field.
Thanks John, and I’d seen that page, but was unable to get it working. Do you have any examples of fully-functional code that’s been written using the append action? Thanks!!!
There are very few examples of custom JS that I’m aware of. The only one I could find right now is https://support.advancedcustomfields.com/forums/topic/make-a-true-and-false-switch-flip-another/ which uses the acf.add_action function to add actions to fields.
That’s a great help — thanks!!! Not solved yet, but this points me in a much better direction! Thanks!
More custom JS examples for ACF would be extremely helpful, but they are currently hard to find.
I do have some examples, but they all go an a completely different direction. I generally add custom JS by extending the acf objects, like I said, a completely different path than what’s given by the ACF developer. https://github.com/Hube2/acf-dynamic-ajax-select-example
Hi Andydeemer, I have a problem just like you. Do you have a solution?