Skip to content

Commit 3b23786

Browse files
saifsultancclaygriffiths
authored andcommitted
gpcc-copy-label.js: Fixed an issue with copying labels from checkbox selections.
1 parent 2eb095f commit 3b23786

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

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

+12-14
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,19 @@
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();
2121
} else if ( $source.is( '.gfield_checkbox') ) {
22-
// Since multiple checkboxes maybe selected, make sure individual checkbox values do not have whitespaces.
23-
values = value.split( ' ' );
24-
var labelArray = [];
25-
values.forEach( function ( value ) {
26-
$input = $( 'input[value="' + value + '"]' );
27-
var labelElement = $( 'label[for="' + $input.attr( 'id' ) + '"]' );
28-
labelArray.push( labelElement.text() );
22+
$inputs= $source.find( 'input:checked' );
23+
var checkedLabels = [];
24+
$inputs.each( function () {
25+
var label = $(this).next('label').text();
26+
checkedLabels.push( label );
2927
});
30-
value = labelArray.join( ' ' );
28+
value = checkedLabels.join(' ');
3129
}
32-
return value;
30+
return value;
3331
} );

0 commit comments

Comments
 (0)