Skip to content
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

gpcc-copy-label.js: Fixed an issue with copying labels from checkbox selections. #716

Merged
merged 3 commits into from
Oct 10, 2023
Merged
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
22 changes: 15 additions & 7 deletions gp-copy-cat/gpcc-copy-label.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,24 @@
* Use this snippet to copy the label instead of the value.
*
* Instructions:
* 1. Install our free Custom Javascript for Gravity Forms plugin.
* 1. Install our free Custom Javascript for Gravity Forms plugin.
* Download the plugin here: https://gravitywiz.com/gravity-forms-custom-javascript/
* 2. Copy and paste the snippet into the editor of the Custom Javascript for Gravity Forms plugin.
*/
gform.addFilter( 'gppc_copied_value', function( value, $elem, data ) {
$source = jQuery( '#input_' + data.sourceFormId + '_' + data.source );
if( $source.is( 'select' ) ) {
value = $source.find( 'option:selected' ).text();
} else if( $source.is( '.gfield_radio' ) ) {
value = $( '.gfield-choice-input:checked + label' ).text();
$source = jQuery( '#input_' + data.sourceFormId + '_' + data.source );
if( $source.is( 'select' ) ) {
value = $source.find( 'option:selected' ).text();
} else if( $source.is( '.gfield_radio' ) ) {
value = $( '.gfield-choice-input:checked + label' ).text();
} else if ( $source.is( '.gfield_checkbox') ) {
$inputs = $source.find( 'input:checked' );
var checkedLabels = [];
$inputs.each( function () {
var label = $(this).next('label').text();
checkedLabels.push( label );
});
value = checkedLabels.join(' ');
}
return value;
return value;
} );
Loading