Last active
May 18, 2023 12:14
-
-
Save matty0501/ff8fb91dafb0a43e171ca8cc74a1f61a to your computer and use it in GitHub Desktop.
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 for List Field Drop Downs" snippet - https://github.com/gravitywiz/snippet-library/blob/master/gp-copy-cat/gpcc-copy-label-list-field-drop-downs.js | |
*/ | |
/** | |
* Apply snippet to single Copy Cat | |
* | |
* In this example, the snippet will apply only in this case: | |
* - Copying Field ID 1 to Field ID 2 | |
*/ | |
gform.addFilter( 'gppc_copied_value', function( value, $elem, data ) { | |
if( data.source == 1 && data.target == 2 ){ // Configure this line | |
if ( $.isNumeric( value ) ) { | |
var found = jQuery( '#field_' + data.sourceFormId + '_' + data.source ).find( 'option[value="' + value + '"]' ).text(); | |
value = found ? found : value; | |
} | |
} | |
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 == 2 ) | |
* | |
* In this example, the snippet will apply in these cases: | |
* - Copying Field ID 1 to Field ID 2 | |
* - 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 == 2 ) || ( data.source == 7 && data.target == 9 ) || ( data.source == 5 && data.target == 8 ) ){ // Configure this line | |
if ( $.isNumeric( value ) ) { | |
var found = jQuery( '#field_' + data.sourceFormId + '_' + data.source ).find( 'option[value="' + value + '"]' ).text(); | |
value = found ? found : value; | |
} | |
} | |
return value; | |
} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment