From bfdb20767f720b5464fc68fb2037854a308d314b Mon Sep 17 00:00:00 2001 From: Saif Sultan Date: Thu, 10 Apr 2025 19:38:43 +0530 Subject: [PATCH] `gpnf-limit-entry-min-max-from-field.php]`: Fixed an issue with entry min max recalculation logic not working. --- .../gpnf-limit-entry-min-max-from-field.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/gp-nested-forms/gpnf-limit-entry-min-max-from-field.php b/gp-nested-forms/gpnf-limit-entry-min-max-from-field.php index aa60603e..8e0e9668 100644 --- a/gp-nested-forms/gpnf-limit-entry-min-max-from-field.php +++ b/gp-nested-forms/gpnf-limit-entry-min-max-from-field.php @@ -154,9 +154,18 @@ public function output_script() { }); gform.addAction( 'gform_input_change', function( el, formId, fieldId ) { + // Force Knockout to recalculate the max when the number has changed if ( el.id === maxFieldId ) { - // Force Knockout to recalculate the max when the number has changed - window[ 'GPNestedForms_{0}_{1}'.gformFormat( self.parentFormId, self.nestedFormFieldId ) ].viewModel.entries.valueHasMutated(); + const gpnfViewModel = window[ 'GPNestedForms_{0}_{1}'.gformFormat( self.parentFormId, self.nestedFormFieldId ) ]?.viewModel; + + // Use the standard Knockout method if available. + if ( typeof gpnfViewModel?.entries?.valueHasMutated === 'function' ) { + gpnfViewModel.entries.valueHasMutated(); + // Fallback for scenarios where 'entries' is a computed observable (no valueHasMutated). + // Trigger reactivity by reassigning a shallow copy of the observable array. + } else if ( typeof gpnfViewModel?.entriesRaw === 'function' ) { + gpnfViewModel.entriesRaw( gpnfViewModel.entriesRaw()?.slice() ); + } } } );