|
13 | 13 | * 2. Copy and paste the snippet into the editor of the Custom Javascript for Gravity Forms plugin.
|
14 | 14 | */
|
15 | 15 | 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 | 21 | } 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 ); |
29 | 27 | });
|
30 |
| - value = labelArray.join( ' ' ); |
| 28 | + value = checkedLabels.join(' '); |
31 | 29 | }
|
32 |
| - return value; |
| 30 | + return value; |
33 | 31 | } );
|
0 commit comments