From 1469b576a3cd11a9f674f75b554320aa2367a3a1 Mon Sep 17 00:00:00 2001 From: David Smith Date: Thu, 22 Dec 2022 21:59:25 -0500 Subject: [PATCH 1/2] Added support for counting Radio Button choices. Can be used to count the number of Radio Button fields with a specific choice checked (e.g. "N/A"). --- gravity-forms/gw-choice-counter.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/gravity-forms/gw-choice-counter.php b/gravity-forms/gw-choice-counter.php index 878c640a4..f5860fe49 100644 --- a/gravity-forms/gw-choice-counter.php +++ b/gravity-forms/gw-choice-counter.php @@ -75,7 +75,7 @@ function output_script() { $parentForm.off( 'click', choiceFieldSelector, self.updateChoiceEventHander ); $parentForm.off( 'change', choiceFieldSelector, self.updateChoiceEventHander ); - if ( self.isCheckboxField( $choiceField ) ) { + if ( self.isCheckableField( $choiceField ) ) { $parentForm.on( 'click', choiceFieldSelector, self.updateChoiceEventHandler ); } else { $parentForm.on( 'change', choiceFieldSelector, self.updateChoiceEventHandler ); @@ -104,8 +104,8 @@ function output_script() { } ); }; - self.isCheckboxField = function( $field ) { - return Boolean( $field.find( 'input[type="checkbox"]' ).length ); + self.isCheckableField = function($field ) { + return Boolean( $field.find( ':checkbox, :radio' ).length ); } self.updateChoiceCount = function( formId, choiceFieldIds, countFieldId, values ) { @@ -118,15 +118,15 @@ function output_script() { var $choiceField = $( '#input_' + formId + '_' + choiceFieldIds[ i ] ); if ( ! values ) { // If no values provided in the config, just get the number of checkboxes checked. - if ( self.isCheckboxField( $choiceField ) ) { - count += $choiceField.find( 'input[type="checkbox"]:checked' ).not(' #choice_' + choiceFieldIds[ i ] + '_select_all').length; + if ( self.isCheckableField( $choiceField ) ) { + count += $choiceField.find( ':checked' ).not(' #choice_' + choiceFieldIds[ i ] + '_select_all').length; } else { count += $choiceField.find( 'option:selected' ).length; } } else { // When values are provided, match the values before adding them to count. var selectedValues = []; - $choiceField.find( 'input[type="checkbox"]:checked' ).each( function( k, $selectedChoice ) { + $choiceField.find( ':checked' ).each( function( k, $selectedChoice ) { selectedValues.push( $selectedChoice.value ); }); values.forEach( function( val ) { From e7f96d52e0c81ae377ffa9ac0bb5ab9f66d1caad Mon Sep 17 00:00:00 2001 From: David Smith Date: Thu, 22 Dec 2022 22:02:24 -0500 Subject: [PATCH 2/2] ~ Bumped version. --- gravity-forms/gw-choice-counter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gravity-forms/gw-choice-counter.php b/gravity-forms/gw-choice-counter.php index f5860fe49..29bff62b9 100644 --- a/gravity-forms/gw-choice-counter.php +++ b/gravity-forms/gw-choice-counter.php @@ -7,7 +7,7 @@ * Get the total number of checkboxes checked or multi-select options selected. Useful when wanting to apply conditional * logic based on those totals. * - * @version 1.1 + * @version 1.2 * @author David Smith * @license GPL-2.0+ * @link http://gravitywiz.com/