Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 3 additions & 22 deletions experimental/gpnf-add-child-entries-to-the-top.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,5 @@
/**
* Gravity Perks // Nested Forms // Subscribe to Child Entry Updates
* https://gravitywiz.com/documentation/gravity-forms-nested-forms/
* We're no longer using the experimental folder for experimental snippets. 🚧
* You can now find the snippet here:
* https://github.com/gravitywiz/snippet-library/blob/master/gp-nested-forms/gpnf-add-child-entries-to-the-top.js
*/
// Get your Nested Forms JavaScript instance where "4" is the Nested Form field ID.
var gpnf = window.GPNestedForms_GFFORMID_13;
var entryCount = 0;
var doingItLive = false;

gpnf.viewModel.entries.subscribe( function( entries ) {
if ( ! doingItLive ) {
entryCount = entries.length;
}
}, null, 'beforeChange' );

gpnf.viewModel.entries.subscribe( function( entries ) {
// Check if an entry was added.
if ( ! doingItLive && entries.length > entryCount ) {
doingItLive = true;
gpnf.viewModel.entries.splice( 0, 0, gpnf.viewModel.entries.pop() );
entryCount = entries.length;
doingItLive = false;
}
} );
Loading