-
Notifications
You must be signed in to change notification settings - Fork 91
/
Copy pathgpasc-radio-button-toggle.js
54 lines (47 loc) · 1.73 KB
/
gpasc-radio-button-toggle.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/**
* Gravity Perks // Advanced Save and Continue // Toggle GPASC with Radio Buttons
* https://gravitywiz.com/documentation/gravity-forms-advanced-save-continue/
*
* This snippet allows you to toggle GPASC client side with radio buttons.
*
* Instructions:
* 1. Add snippet to form using https://gravitywiz.com/gravity-forms-code-chest/
* 2. Customize radioButtonFieldId to the field you want this to apply to.
* 3. Customize enableInputId and disableInputId per the comments above each variable.
*/
// change this to match your form ID
var formId = GFFORMID;
// change this to match the radio button field you'd like to use to control this
var radioButtonFieldId = 1;
// change this to match the radio button input ID you'd like to use to enable GPASC
var enableInputId = 0;
// change this to match the radio button input ID you'd like to use to disable GPASC
var disableInputId = 1;
var gpascInstanceKey = 'GPASC_' + formId;
var enabledSelector = '#choice_' + formId + '_' + radioButtonFieldId + '_' + enableInputId;
var disabledSelector = '#choice_' + formId + '_' + radioButtonFieldId + '_' + disableInputId;
function enableGPASC() {
if (window[gpascInstanceKey] && window[gpascInstanceKey].enable) {
window[gpascInstanceKey].enable();
}
}
function disableGPASC() {
if (window[gpascInstanceKey] && window[gpascInstanceKey].enable) {
window[gpascInstanceKey].disable({ resetCookieModal: true });
}
}
if ($(enabledSelector).prop('checked')) {
enableGPASC()
} else if ($(disabledSelector).prop('checked')) {
disableGPASC();
}
$(enabledSelector).on('change', function(event) {
if (event.target.checked) {
enableGPASC();
}
})
$(disabledSelector).on('change', function(event) {
if (event.target.checked) {
disableGPASC();
}
})