-
Notifications
You must be signed in to change notification settings - Fork 91
/
Copy pathgw-all-checkboxes-checked.js
33 lines (30 loc) · 1.2 KB
/
gw-all-checkboxes-checked.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/**
* Gravity Wiz // Gravity Forms // Evaluate if All Checkboxes are Checked.
* https://gravitywiz.com/
*
* Instruction Video: https://www.loom.com/share/e69c545358ca44748735ec98eee76a40
*
* * Instructions:
* 1. Install our free Custom Javascript for Gravity Forms plugin.
* Download the plugin here: https://gravitywiz.com/gravity-forms-code-chest/
* 2. Copy and paste the snippet into the editor of the Custom Javascript for Gravity Forms plugin.
*/
// Update "1" and "2" to the checkbox field id and hidden field id on your form
var checkboxFieldId = 1;
var hiddenFieldId = 2;
function checkCheckboxCounts() {
var $checkboxField = $( `#input_GFFORMID_${checkboxFieldId}` );
$checkboxField.find( 'input' ).on( 'change', function() {
var totalCheckboxes = $checkboxField.find( 'input' ).length;
var checkedCheckboxes = $checkboxField.find( 'input:checked' ).length;
if ( totalCheckboxes === checkedCheckboxes ) {
$('#input_GFFORMID_' + hiddenFieldId).val(1).trigger( 'change' );
} else {
$('#input_GFFORMID_' + hiddenFieldId).val(0).trigger( 'change' );
}
} );
}
$( document ).on( 'gppa_updated_batch_fields', function() {
checkCheckboxCounts();
} );
checkCheckboxCounts();