Last active
May 18, 2023 12:06
-
-
Save matty0501/bc7492642ab7f09bcc6076c197b2b503 to your computer and use it in GitHub Desktop.
Selectively apply Gravity Perks Copy Cat "Copy Label (instead of Value)" snippet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Selectively apply Gravity Perks Copy Cat "Copy Label (instead of Value)" snippet - https://github.com/gravitywiz/snippet-library/blob/master/gp-copy-cat/gpcc-copy-label.js | |
*/ | |
/** | |
* Apply snippet to single Copy Cat | |
* | |
* In this example, the snippet will apply only in this case: | |
* - Copying Field ID 3 to Field ID 4 | |
*/ | |
gform.addFilter( 'gppc_copied_value', function( value, $elem, data ) { | |
if( data.source == 3 && data.target == 4 ){ // Configure this line | |
$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(); | |
} | |
} | |
return value; | |
} ); | |
/** | |
* Apply snippet to multiple Copy Cats | |
* | |
* In the configuration line for this example, we have 3 sets of Copy Cat fields | |
* | |
* Each set of fields is contained in brackets like this: ( data.source == 1 && data.target == 4 ) | |
* | |
* In this example, the snippet will apply in these cases: | |
* - Copying Field ID 1 to Field ID 4 | |
* - Copying Field ID 7 to Field ID 9 | |
* - Copying Field ID 5 to Field ID 8 | |
*/ | |
gform.addFilter( 'gppc_copied_value', function( value, $elem, data ) { | |
if( ( data.source == 1 && data.target == 4 ) || ( data.source == 7 && data.target == 9 ) || ( data.source == 5 && data.target == 8 ) ){ // Configure this line | |
$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(); | |
} | |
} | |
return value; | |
} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment