Skip to content

Commit 451c100

Browse files
authored
gpnf-custom-add-entry-button-labels-depending-on-child-entry-count.php: Added a new snippet to customize the "Add Entry" button label depending on whether the field has child entries or not.
1 parent bc2d6e9 commit 451c100

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
/**
3+
* Gravity Perks // Nested Forms // Add Custom Label for "Add Entry" Button Depending on Child Entry Count
4+
* https://gravitywiz.com/documentation/gravity-forms-nested-forms/
5+
*
6+
* Use this snippet to set a custom "Add Entry" button label when there are no child entries. In this example, the button
7+
* will read "Add First Entry" if there are no child entries and "Add Another Entry" if there is at least one child entry.
8+
*/
9+
// Update "123" to your parent form ID.
10+
add_filter( 'gpnf_template_args_123', function( $args ) {
11+
if ( isset( $args['add_button'] ) ) {
12+
$search = 'data-bind="';
13+
$replace = $search . sprintf( 'text: ! entries().length ? `Add First %1$s` : `Add Another %1$s`, ', $args['field']->get_item_label() );
14+
$args['add_button'] = str_replace( $search, $replace, $args['add_button'] );
15+
}
16+
return $args;
17+
} );

0 commit comments

Comments
 (0)