77 * Get the total number of checkboxes checked or multi-select options selected. Useful when wanting to apply conditional
88 * logic based on those totals.
99 *
10- * @version 1.1
10+ * @version 1.2
1111 * @author David Smith <david@gravitywiz.com>
1212 * @license GPL-2.0+
1313 * @link http://gravitywiz.com/
@@ -75,7 +75,7 @@ function output_script() {
7575 $parentForm.off( 'click', choiceFieldSelector, self.updateChoiceEventHander );
7676 $parentForm.off( 'change', choiceFieldSelector, self.updateChoiceEventHander );
7777
78- if ( self.isCheckboxField ( $choiceField ) ) {
78+ if ( self.isCheckableField ( $choiceField ) ) {
7979 $parentForm.on( 'click', choiceFieldSelector, self.updateChoiceEventHandler );
8080 } else {
8181 $parentForm.on( 'change', choiceFieldSelector, self.updateChoiceEventHandler );
@@ -104,8 +104,8 @@ function output_script() {
104104 } );
105105 };
106106
107- self.isCheckboxField = function( $field ) {
108- return Boolean( $field.find( 'input[type=" checkbox"] ' ).length );
107+ self.isCheckableField = function($field ) {
108+ return Boolean( $field.find( ': checkbox, :radio ' ).length );
109109 }
110110
111111 self.updateChoiceCount = function( formId, choiceFieldIds, countFieldId, values ) {
@@ -118,15 +118,15 @@ function output_script() {
118118 var $choiceField = $( '#input_' + formId + '_' + choiceFieldIds[ i ] );
119119 if ( ! values ) {
120120 // If no values provided in the config, just get the number of checkboxes checked.
121- if ( self.isCheckboxField ( $choiceField ) ) {
122- count += $choiceField.find( 'input[type="checkbox"] :checked' ).not(' #choice_' + choiceFieldIds[ i ] + '_select_all').length;
121+ if ( self.isCheckableField ( $choiceField ) ) {
122+ count += $choiceField.find( ':checked' ).not(' #choice_' + choiceFieldIds[ i ] + '_select_all').length;
123123 } else {
124124 count += $choiceField.find( 'option:selected' ).length;
125125 }
126126 } else {
127127 // When values are provided, match the values before adding them to count.
128128 var selectedValues = [];
129- $choiceField.find( 'input[type="checkbox"] :checked' ).each( function( k, $selectedChoice ) {
129+ $choiceField.find( ':checked' ).each( function( k, $selectedChoice ) {
130130 selectedValues.push( $selectedChoice.value );
131131 });
132132 values.forEach( function( val ) {
0 commit comments