Stream to Paragraph Field

Stream OpenAI responses from the OpenAI Stream field to a Paragraph (or Single Line Text) field instead. Useful when wanting to provide a starting point for users while allowing them to edit the final result.

Instructions

  1. Install this snippet with our free Custom JavaScript plugin. https://gravitywiz.com/gravity-forms-custom-javascript/

  2. Update the variables to match your own field IDs.

Code

Filename: gcoai-stream-to-paragraph-field.js

/**
 * Gravity Connect // OpenAI // Stream to Paragraph Field
 * https://gravitywiz.com/documentation/gravity-connect-openai/
 *
 * Stream OpenAI responses from the OpenAI Stream field to a Paragraph (or Single Line Text)
 * field instead. Useful when wanting to provide a starting point for users while allowing them
 * to edit the final result.
 * 
 * Instruction Video: https://www.loom.com/share/f793319da7e449a8b01e5a8c077e24c7
 *
 * Instructions:
 *
 * 1. Install this snippet with our free Custom JavaScript plugin.
 *    https://gravitywiz.com/gravity-forms-custom-javascript/
 * 
 * 2. Update the variables to match your own field IDs.
 */
var streamFieldId = 1;
var promptFieldId = 2;
var responseFieldId = 3;

var $streamFieldInput = $( `#input_GFFORMID_${streamFieldId}` );
var $streamButton     = $streamFieldInput.parents( '.gfield' ).find( '.gcoai-trigger' );

$streamFieldInput.on( 'change', function() {
    $( `#input_GFFORMID_${responseFieldId}` ).val( this.value );
} );

$streamButton
	.clone()
	.attr( 'style', 'margin-top: var(--gf-label-space-primary, 8px);' )
	.on( 'click', function() {
		$streamButton.trigger( 'click' )
	} )
	.insertAfter( $( `#input_GFFORMID_${promptFieldId}` ) )

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.