Created
October 3, 2025 13:09
-
-
Save chrisegg/45396bfcabf865834d37a8fccad6e50a to your computer and use it in GitHub Desktop.
Add placeholder text to a Gravity Forms list field, supports single field or multiple columns.
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
| /** | |
| * Description: Add placeholder text to Gravity Forms list fields. | |
| * Version: 1.0 | |
| * Author: Chris Egglelston | |
| * Website: https://gravityranger.com | |
| */ | |
| <script> | |
| const gfListPlaceholderConfig = { | |
| formId: 401, //replace 401 with your forms ID | |
| fieldId: 1, // replace 1 with your List field ID | |
| columns: ['First Name', 'Last Name', 'Email'] // Add your desired placeholders for each column | |
| }; | |
| document.addEventListener('DOMContentLoaded', function () { | |
| // Validate config | |
| if (!gfListPlaceholderConfig.formId || !gfListPlaceholderConfig.fieldId || !gfListPlaceholderConfig.columns.length) { | |
| console.warn('Invalid Gravity Forms list field configuration'); | |
| return; | |
| } | |
| const fieldSelector = `#field_${gfListPlaceholderConfig.formId}_${gfListPlaceholderConfig.fieldId}`; | |
| const listContainer = document.querySelector(fieldSelector); | |
| if (!listContainer) { | |
| console.warn(`List field container not found for form ${gfListPlaceholderConfig.formId}, field ${gfListPlaceholderConfig.fieldId}`); | |
| return; | |
| } | |
| function addPlaceholders() { | |
| const inputs = document.querySelectorAll(`#field_${gfListPlaceholderConfig.formId}_${gfListPlaceholderConfig.fieldId} .ginput_list input`); | |
| if (!inputs.length) { | |
| console.warn('No inputs found in list field'); | |
| return; | |
| } | |
| inputs.forEach((input, index) => { | |
| if (input && input.placeholder === '') { | |
| const colIndex = index % gfListPlaceholderConfig.columns.length; | |
| input.placeholder = gfListPlaceholderConfig.columns[colIndex]; | |
| } | |
| }); | |
| } | |
| // Initial run | |
| addPlaceholders(); | |
| // Re-run when a new list row is added | |
| listContainer.addEventListener('click', function (e) { | |
| if (e.target && e.target.classList.contains('add_list_item')) { | |
| setTimeout(addPlaceholders, 100); // Wait for row to render | |
| } | |
| }); | |
| }); | |
| </script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment