Skip to content

Commit 5384df1

Browse files
authored
gpcc-copy-option-to-checkbox.js: Added a snippet to copy Option field selected value to Checkbox field.
1 parent 1d6d31c commit 5384df1

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* Gravity Perks // Copy Cat // Copy Option to Checkbox
3+
* https://gravitywiz.com/documentation/gravity-forms-copy-cat/
4+
*
5+
* Use this snippet to copy option field value to a Checkbox field.
6+
*
7+
* Instructions Video: https://www.loom.com/share/0897b49b88ca43be9590e2aef13de50a
8+
*
9+
* Instructions:
10+
*
11+
* 1. Install this snippet with our free Code Chest plugin.
12+
* https://gravitywiz.com/gravity-forms-code-chest/
13+
*/
14+
gform.addFilter('gpcc_copied_value', function(value, $elem, data) {
15+
if (!data || !data.sourceFormId || !data.source) {
16+
return value;
17+
}
18+
19+
const sourcefieldId = '#field_' + data.sourceFormId + '_' + data.source;
20+
const $sourceField = $(sourcefieldId);
21+
22+
if ($sourceField.length && $sourceField.hasClass('gfield--type-option')) {
23+
if (Array.isArray(value)) {
24+
value = value.map(item => typeof item === 'string' ? item.split('|')[0] : item);
25+
}
26+
}
27+
28+
return value;
29+
});

0 commit comments

Comments
 (0)