Skip to content

Commit 0e5d365

Browse files
saifsultancclaygriffiths
authored andcommitted
gpcc-copy-label.js: Fixed an issue with copying labels from checkbox selections.
1 parent a36940a commit 0e5d365

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

gp-copy-cat/gpcc-copy-label.js

+15-7
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,24 @@
88
* Use this snippet to copy the label instead of the value.
99
*
1010
* Instructions:
11-
* 1. Install our free Custom Javascript for Gravity Forms plugin.
11+
* 1. Install our free Custom Javascript for Gravity Forms plugin.
1212
* Download the plugin here: https://gravitywiz.com/gravity-forms-custom-javascript/
1313
* 2. Copy and paste the snippet into the editor of the Custom Javascript for Gravity Forms plugin.
1414
*/
1515
gform.addFilter( 'gppc_copied_value', function( value, $elem, data ) {
16-
$source = jQuery( '#input_' + data.sourceFormId + '_' + data.source );
17-
if( $source.is( 'select' ) ) {
18-
value = $source.find( 'option:selected' ).text();
19-
} else if( $source.is( '.gfield_radio' ) ) {
20-
value = $( '.gfield-choice-input:checked + label' ).text();
16+
$source = jQuery( '#input_' + data.sourceFormId + '_' + data.source );
17+
if( $source.is( 'select' ) ) {
18+
value = $source.find( 'option:selected' ).text();
19+
} else if( $source.is( '.gfield_radio' ) ) {
20+
value = $( '.gfield-choice-input:checked + label' ).text();
21+
} else if ( $source.is( '.gfield_checkbox') ) {
22+
$inputs = $source.find( 'input:checked' );
23+
var checkedLabels = [];
24+
$inputs.each( function () {
25+
var label = $(this).next('label').text();
26+
checkedLabels.push( label );
27+
});
28+
value = checkedLabels.join(' ');
2129
}
22-
return value;
30+
return value;
2331
} );

0 commit comments

Comments
 (0)