Description
The gform/repeater/post_item_add action fires after a new repeater item is successfully added to the form. It allows developers to reinitialize JavaScript components such as datepickers, rich text editors, or custom field behaviors on the newly cloned fields.
Usage
Asynchronous
Use this when reinitializing components or performing operations that require async logic, such as waiting for an API to load before binding behaviors.
document.addEventListener('gform/repeater/post_item_add', async (event) => {
const { clone, container } = event.detail;
// Do something.
});
Synchronous
Use this when running immediate DOM operations, such as re-binding validation, tooltips, or simple UI adjustments.
document.addEventListener('gform/repeater/post_item_add', (event) => {
const { clone, container } = event.detail;
// Do something.
});
Parameters
| Parameter | Type | Description |
|---|---|---|
| clone | HTMLElement | The newly added repeater item element cloned from the template. |
| container | HTMLElement | The repeater container element holding the item and its siblings. |
Examples
Reinitialize datepickers on new repeater items.
document.addEventListener('gform/repeater/post_item_add', (event) => {
const { clone } = event.detail;
if (typeof window.gformInitDatepicker === 'function') {
clone.querySelectorAll('.hasDatepicker').forEach((el) => {
el.classList.remove('initialized', 'hasDatepicker');
});
window.gformInitDatepicker();
}
});
Placement
Reference the article Adding JavaScript Code to the Frontend of Your Site.
Since
This action was added in Gravity Forms v3.2.0.
Source Code
This action is triggered in assets/js/src/theme/fields/repeater/index.js