Skip to content

gpcc-copy-option-to-checkbox.js: Added a snippet to copy Option field selected value to Checkbox field. #1124

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions gp-copy-cat/gpcc-copy-option-to-checkbox.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* Gravity Perks // Copy Cat // Copy Option to Checkbox
* https://gravitywiz.com/documentation/gravity-forms-copy-cat/
*
* Use this snippet to copy option field value to a Checkbox field.
*
* Instructions Video: https://www.loom.com/share/0897b49b88ca43be9590e2aef13de50a
*
* Instructions:
*
* 1. Install this snippet with our free Code Chest plugin.
* https://gravitywiz.com/gravity-forms-code-chest/
*/
gform.addFilter('gpcc_copied_value', function(value, $elem, data) {
if (!data || !data.sourceFormId || !data.source) {
return value;
}

const sourcefieldId = '#field_' + data.sourceFormId + '_' + data.source;
const $sourceField = $(sourcefieldId);

if ($sourceField.length && $sourceField.hasClass('gfield--type-option')) {
if (Array.isArray(value)) {
value = value.map(item => typeof item === 'string' ? item.split('|')[0] : item);
}
}

return value;
});
Loading