gform/repeater/item_pre_add

Description

The gform/repeater/item_pre_add filter allows developers to modify a repeater item’s DOM element before it is added to a Gravity Forms repeater field.

Usage

Asynchronous

The filter now supports asynchronous logic, allowing developers to perform operations such as API calls or other async tasks before the repeater item is added.

// Asynchronous handler
gform.utils.addAsyncFilter( 'gform/repeater/item_pre_add', async ( clone ) => {
  await someAsyncOperation(); // e.g., fetch to prefill values
  clone.querySelector('.gfield_repeater_cell:nth-child(2) input').value = 'Async value';
  return clone;
} );

Synchronous

// Synchronous handler
gform.utils.addAsyncFilter( 'gform/repeater/item_pre_add', ( clone ) => {
  // `clone` is an HTMLElement created by cloneNode(true)
  clone.querySelector('.gfield_repeater_cell:nth-child(2) input').value = 'Your new value';
  return clone;
} );
ParameterTypeDescription
cloneHTMLElementThe repeater item element created by cloneNode(true). Must be returned (possibly modified), or resolved via a Promise.

Examples

Set the value of an input.

This example shows how you can set the value of the second input in a Repeater Field group.

gform.utils.addAsyncFilter('gform/repeater/item_pre_add', async function (clone) {
    // Set the value of the second input in the repeater item
    clone.querySelector('.gfield_repeater_cell:nth-child(2) input').value = 'Your new value';
    return clone;
});

Placement

Reference the article Adding JavaScript Code to the Frontend of Your Site.

Since

The asynchronous version of the filter was added in Gravity Forms 3.2.0

Source Code

Since Gravity Forms 3.2.0 this filter is located in assets/js/src/theme/fields/repeater/index.js, it was previously located in js/gravityforms.js.