Copy List Field Rows as New Lines

Use this snippet to copy List field rows as new lines into a Paragraph field.

Screenshot: https://gwiz.io/3wWlUts

Code

Filename: gpcc-list-rows-as-new-lines.js

/**
 * Gravity Perks // Copy Cat // Copy List Field Rows as New Lines
 * https://gravitywiz.com/documentation/gravity-forms-copy-cat/
 *
 * Use this snippet to copy List field rows as new lines into a Paragraph field.
 *
 * Screenshot: https://gwiz.io/3wWlUts
 */
gform.addFilter( 'gpcc_copied_value', function( value, $targetElem, field, sourceValues ) {
	// Update "3" to your Paragraph field ID.
	if ( field.sourceFormId != GFFORMID || field.target != 3 ) {
		return value;
	}
	sourceValues = structuredClone( sourceValues );
	// Update "3" to the number of columns in your List field.
	var columnCount = 3;
	var lines = [];
	var line  = [];
	while ( sourceValues.length ) {
		line.push( sourceValues.shift() );
		if ( line.length == columnCount ) {
			lines.push( line.join( ' ' ) );
			line = [];
		}
	}
	value = lines.join( "\n" );
	return value;
} );

Leave a Reply

Your email address will not be published. Required fields are marked *

  • Trouble installing this snippet? See our troubleshooting tips.
  • Need to include code? Create a gist and link to it in your comment.
  • Reporting a bug? Provide a URL where this issue can be recreated.

By commenting, I understand that I may receive emails related to Gravity Wiz and can unsubscribe at any time.