Support

Account

Home Forums General Issues Extending field in JavaScript, can I call the parent method? Reply To: Extending field in JavaScript, can I call the parent method?

  • When extending fields in JavaScript using ACF’s model system, it’s absolutely possible to call the parent method from within your extended method, similar to how you would in PHP with parent::method().

    You can do this by using this._super() in your child method to invoke the parent method. For example, in your case, to extend the removeAttachment function, you could structure it like this:

    javascript
    Copy code
    const ImageExtends = acf.models.ImageField.extend({
    removeAttachment: function() {
    // Call the parent method
    this._super();

    // Your extra logic here
    console.log(“Doing extra work after removing attachment…”);
    }
    });
    The this._super() call refers to the parent method, allowing you to avoid duplicating its logic. This should help you keep your calendar code clean and modular.

    Hope this helps !