Support

Account

Home Forums Add-ons Repeater Field Overriding Repeater function

Unread

Overriding Repeater function

  • Hello Support community.

    ok I’m pretty new to ACF and I’m trying to extent the repeater field.

    essentially what i want to do is overwrite the “onClickAdd” function. I have and external JS file added through the php
    add_action("acf/input/admin_enqueue_scripts", array($this, 'admin_enqueue_scripts'), 10, 0);

    at the top of this .js file I have

       acf.models.RepeaterField.extend({
           
            onClickAdd: function( e, $el ){
                console.log("overridden");
                // validate
                if( !this.validateAdd() ) {
                    return false;
                }
    
                // add above row
                if( $el.hasClass('acf-icon') ) {
                    this.add({
                        before: $el.closest('.acf-row')
                    });
    
                    // default
                } else {
                    this.add();
                }
            },
        });

    But when i click on the add row button. Nothing is logged in the console. What am i missing here?

    i have tried editing the prototype directly by

    acf.models.RepeaterField.prototype = $.extend(acf.models.RepeaterField.prototype, {onClickAdd: function( e, $el ){
    
            console.log("324 console.");
    
            // validate
            if( !this.validateAdd() ) {
                return false;
            }
    
            // add above row
            if( $el.hasClass('acf-icon') ) {
                this.add({
                    before: $el.closest('.acf-row')
                });
    
                // default
            } else {
                this.add();
            }
        }})

    but I’m also not getting anything in the console. Do i need to add this function in an action or filter to get it to work?

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.