ACF has plenty of PHP hooks, but some basic JS hooks are still missing. I was looking for an event that is fired when a value of a field is changed, but according to this topic, there’s no such a thing.
Some hooks that might be useful:
- change – fired when the field value is changed
- remove – fired when the field value is removed
- before_validation – fired before the validation
- after_validation – fired after the validation
- befor_add_row – fired before a repeater row is added
- after_add_row – fired after a repeater row is added
- befor_remove_row – fired before a repeater row is removed
- after_remove_row – fired after a repeater row is removed
- befor_add_layout – fired before a flexible field layout is added
- after_add_layout – fired before a flexible field layout is added
- befor_remove_layout – fired before a flexible field layout is removed
- after_remove_layout – fired after a flexible field layout is removed
This right here – is brilliant. I’ve had so many issues with the current JS hooks (for instance, the remove hook fires every time I add a new row to a repeater, why?).
Also, the current remove hook fires BEFORE the row is even removed (due to the animation), but I need it to fire after since my JS removes the row numbers and replaces them with icons and the row numbers get regenerated AFTER the animation.
IMO, there’s a room for many improvements in the JS hooks. Not only adding missing hooks, but also providing more data (like a previous input value, field name, etc) in the callback function would be welcome.