Skip to content

Commit 00117a8

Browse files
authored
gpnf-limit-entry-min-max-from-field.php]: Fixed an issue with entry min max recalculation logic not working.
1 parent c50ec8d commit 00117a8

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

gp-nested-forms/gpnf-limit-entry-min-max-from-field.php

+11-2
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,18 @@ public function output_script() {
154154
});
155155

156156
gform.addAction( 'gform_input_change', function( el, formId, fieldId ) {
157+
// Force Knockout to recalculate the max when the number has changed
157158
if ( el.id === maxFieldId ) {
158-
// Force Knockout to recalculate the max when the number has changed
159-
window[ 'GPNestedForms_{0}_{1}'.gformFormat( self.parentFormId, self.nestedFormFieldId ) ].viewModel.entries.valueHasMutated();
159+
const gpnfViewModel = window[ 'GPNestedForms_{0}_{1}'.gformFormat( self.parentFormId, self.nestedFormFieldId ) ]?.viewModel;
160+
161+
// Use the standard Knockout method if available.
162+
if ( typeof gpnfViewModel?.entries?.valueHasMutated === 'function' ) {
163+
gpnfViewModel.entries.valueHasMutated();
164+
// Fallback for scenarios where 'entries' is a computed observable (no valueHasMutated).
165+
// Trigger reactivity by reassigning a shallow copy of the observable array.
166+
} else if ( typeof gpnfViewModel?.entriesRaw === 'function' ) {
167+
gpnfViewModel.entriesRaw( gpnfViewModel.entriesRaw()?.slice() );
168+
}
160169
}
161170
} );
162171

0 commit comments

Comments
 (0)