Created
January 11, 2017 12:15
-
-
Save ensostyle/24c9ace4526c9ac63f78bfdd8a861570 to your computer and use it in GitHub Desktop.
Count the number of rows in a Gravity Forms list field and store the result in another field.
This file contains 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
<script> | |
function ListFieldRowCount( listField, totalField ) { | |
var totalRows = jQuery( listField ).find('table.gfield_list tbody tr').length; | |
jQuery( totalField ).val( totalRows ).change(); | |
} | |
function ListFieldRowTotal( formId, fieldId, totalFieldId ) { | |
var listField = '#field_' + formId + '_' + fieldId; | |
var totalField = '#input_' + formId + '_' + totalFieldId; | |
ListFieldRowCount( listField, totalField ); | |
jQuery( listField ).on( 'click', '.add_list_item', function() { | |
ListFieldRowCount( listField, totalField ); | |
jQuery( listField + ' .delete_list_item' ).removeProp( 'onclick' ); | |
}); | |
jQuery( listField ).on( 'click', '.delete_list_item', function() { | |
gformDeleteListItem( this, 0 ); | |
ListFieldRowCount( listField, totalField ); | |
}); | |
} | |
ListFieldRowTotal( 158, 1, 7 ); | |
//ListFieldColumnTotal( form id, list field id, result - field id ); | |
// enable dynamic population on field that is to hold result | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Updated for latest Gravityforms version: