Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save matty0501/3c9d3d8e99417324bacb78bd7f13bc00 to your computer and use it in GitHub Desktop.
Save matty0501/3c9d3d8e99417324bacb78bd7f13bc00 to your computer and use it in GitHub Desktop.
/**
* Gravity Perks // GP Nested Forms // Ignore the first `n` child entries with `:count` merge tag modifier
* https://gravitywiz.com/documentation/gravity-forms-nested-forms
*
* Also works with `:total` merge tag modifier
*
* Instructions:
*
* 1. Install this snippet with our free Custom JavaScript plugin.
* https://gravitywiz.com/gravity-forms-custom-javascript/
* 2. Install https://github.com/gravitywiz/snippet-library/blob/master/experimental/gfjs-early-init-scripts.php
* 3. Install accompanying `gpnf-ignore-first-n-entries-in-count.php` PHP snippet: https://gist.github.com/matty0501/651b15e30f2d9ddfc2f5e41319c7c1b3
* 4. Customize form ID, field ID(s), and value check
*/
window.gform.addFilter( 'gpnf_calc_entries', function(entries, match, fieldId, formId, self, formulaField) {
// Only run this for Nested Form Field ID 1 in form ID 123.
if (fieldId !== 1 || formId != 123) {
}
// Only change what entries are used for the calculation done in parent field ID 3
if (formulaField.field_id != 3) {
return entries;
}
// Remove the first `n` entries, and return the modified array. Replace 2 with the number of entries you want to remove.
var filteredEntries = entries.slice( 2 );
return filteredEntries;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment