-
-
Save claygriffiths/05c144159955e62ef29e17000fb7e212 to your computer and use it in GitHub Desktop.
Gravity Perks // GP Copy Cat // Copy Label (instead of Value)
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
<!-- | |
Gravity Perks // GP Copy Cat // Copy Label (instead of Value) | |
http://gravitywiz.com/documentation/gravity-forms-copy-cat/ | |
Instructions: | |
1. Add an HTML field to your form. | |
2. Copy and paste the entire contents of this snippet into the "Content" field setting. | |
--> | |
<script> | |
gform.addFilter( 'gppc_copied_value', function( value, $elem, data, sourceValues ) { | |
$source = jQuery( '#input_' + data.sourceFormId + '_' + data.source ); | |
/* Select inputs */ | |
if( $source.is( 'select' ) ) { | |
value = $source.find( 'option:selected' ).text(); | |
} | |
/* Checkboxes */ | |
if ( $source.hasClass('gfield_checkbox') ) { | |
var labelValues = []; | |
jQuery.each( sourceValues, function( i, value ) { | |
var $checkbox = $source.find(':checkbox[value="' + value + '"]'); | |
labelValues.push($checkbox.siblings('label').text()); | |
} ); | |
/** | |
* Copy Cat rejoins arrays using a space by default. | |
*/ | |
value = labelValues.join(' '); | |
} | |
return value; | |
} ); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment