-
Couldn't load subscription status.
- Fork 92
gw-auto-add-list-row.js: Added snippet to automatically add a new last row to a List field.
#1176
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
saifsultanc
merged 1 commit into
master
from
saif/add/90041-add-auto-add-list-row-snippet
Oct 8, 2025
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| /** | ||
| * Gravity Wiz // Gravity Forms // Auto Add Next List Row | ||
| * https://gravitywiz.com/ | ||
| * | ||
| * Automatically adds a new row to a List field when the user types in the last row. | ||
| * | ||
| * Instruction Video: https://www.loom.com/share/0120ed39296b4e4988c7fdd054af070e | ||
| * | ||
| * Instructions: | ||
| * | ||
| * 1. Install this snippet with our free Code Chest plugin. | ||
| * https://gravitywiz.com/gravity-forms-code-chest/ | ||
| * | ||
| * 2. Adjust the `listSelector` if needed to target a specific List field. | ||
| * | ||
| * 3. That's it — typing in the last row will automatically create the next one. | ||
| */ | ||
|
|
||
| // Selector for the List field container. | ||
| // You can refine this selector to target a specific List field, e.g. `.gfield_list_container input[name="input_6[]"]` | ||
| var listSelector = '.gfield_list_container'; | ||
|
|
||
| /** | ||
| * Bind auto-add behavior to the last row input. | ||
| */ | ||
| function bindAutoAdd() { | ||
| $( listSelector ).each( function() { | ||
| var $container = $( this ); | ||
| var $lastRow = $container.find( '.gfield_list_group' ).last(); | ||
| var $input = $lastRow.find( 'input[type="text"]' ); | ||
|
|
||
| if ( ! $input.length ) { | ||
| return; | ||
| } | ||
|
|
||
| // Remove old handlers inside this container to avoid duplicates. | ||
| $container.find( 'input[type="text"]' ).off( 'input.autoAdd' ); | ||
|
|
||
| // Initialize stored previous value (trimmed). | ||
| $input.data( 'lastVal', ( $input.val() || '' ).trim() ); | ||
|
|
||
| // Bind only to the current last input. | ||
| $input.on( 'input.autoAdd', function() { | ||
| var $this = $( this ); | ||
| var prev = $this.data( 'lastVal' ) || ''; | ||
| var cur = ( $this.val() || '' ).trim(); | ||
|
|
||
| // Trigger add only when it changed from empty → non-empty. | ||
| if ( prev === '' && cur !== '' ) { | ||
| var $addButton = $this.closest( '.gfield_list_group' ).find( '.add_list_item' ); | ||
| if ( $addButton.length ) { | ||
| $addButton.trigger( 'click' ); | ||
| } | ||
| } | ||
|
|
||
| // Update stored value. | ||
| $this.data( 'lastVal', cur ); | ||
| } ); | ||
| } ); | ||
| } | ||
|
|
||
| /** | ||
| * Initial binding. | ||
| */ | ||
| bindAutoAdd(); | ||
|
|
||
| /** | ||
| * Rebind after manual "Add" button click. | ||
| */ | ||
| $( document ).on( 'click', '.add_list_item', function() { | ||
| setTimeout( bindAutoAdd, 50 ); | ||
| } ); | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Support all input types in List fields.
The snippet only targets
input[type="text"], but Gravity Forms List fields can contain textareas, selects, number inputs, and other field types. This significantly limits the snippet's applicability.Apply this diff to support all input types:
Note: Using
.first()ensures we bind to the first input in the row, which is a reasonable trigger point for multi-column list fields.📝 Committable suggestion
🤖 Prompt for AI Agents