Home › Forums › Feature Requests › JS hooks – a reference to DOM node of the rendered item in the callback function › Reply To: JS hooks – a reference to DOM node of the rendered item in the callback function
I found more issues. this in the callback function is a reference to window. IMO the field settings (including field name and field type) should be attached to this.
In the current implementation, this hook isn’t very helpful. It requires too much effort to determine which field’s value was changed. The best way at the moment to find which field is it is to check e.context.name which returns a string like this: acf[field_56d99d7de115e].
// Edit:
An example:
var imageInputOnChange = function ($input) {
// This is the only way to check what field has been changed.
if ($input.context.name !== 'acf[field_56d99d7de115e]') {
return;
}
// Finding the image requires DOM traversing
var $image = $input.closest('.acf-image-uploader').find('img');
// Do something with the $image.
};
acf.add_action('change', imageInputOnChange);
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.