Support

Account

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);