Skip to content

Commit 3aaf75b

Browse files
authored
gppa-populate-child-entries.php: Fixed field does not populate on first load issue.
1 parent cf5dfa5 commit 3aaf75b

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

gp-populate-anything/gppa-populate-child-entries.php

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -120,21 +120,17 @@ public function output_script() {
120120

121121
self.$peidField = $( '#input_{0}_{1}'.gformFormat( self.formId, self.fieldId ) );
122122

123-
if ( typeof window[ 'gpnfSessionPromise_' + self.formId ] === 'undefined' ) {
124-
gform.addAction( 'gpnf_session_initialized', function() {
125-
self.setupPeidField();
126-
} );
127-
} else {
128-
self.setupPeidField();
129-
}
130-
123+
// Make sure cookies are set.
124+
gform.addAction( 'gpnf_session_initialized', function() {
125+
self.setupPeidField();
126+
} );
131127
};
132128

133129
self.setupPeidField = function() {
134130

135-
var gpnfCookie = $.parseJSON( self.getCookie( 'gpnf_form_session_{0}'.gformFormat( self.formId ) ) );
131+
var gpnfCookie = $.parseJSON( self.getCookie( self.cookieName ));
136132

137-
if ( ! self.$peidField.val() ) {
133+
if ( ! self.$peidField.val() && gpnfCookie ) {
138134
self.$peidField
139135
.val( gpnfCookie.hash )
140136
.change();
@@ -182,6 +178,7 @@ public function add_init_script( $form ) {
182178
'formId' => $form['id'],
183179
'fieldId' => $this->get_parent_entry_id_field( $form ),
184180
'nestedFormFieldIds' => wp_list_pluck( $this->get_nested_form_fields( $form ), 'id' ),
181+
'cookieName' => ( new GPNF_Session( $form['id'] ) )->get_cookie_name(),
185182
);
186183

187184
$script = 'new GPPAPopulateChildEntries( ' . json_encode( $args ) . ' );';

0 commit comments

Comments
 (0)