Skip to content

Commit

Permalink
gcoai-stream-to-paragraph-field.js: Updated with support for genera…
Browse files Browse the repository at this point in the history
…ting a first response when exiting the prompt field and populating as RTE-enabled Paragraph fields.
  • Loading branch information
spivurno authored Sep 27, 2024
1 parent fcd66b1 commit c8f740f
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions gc-openai/gcoai-stream-to-paragraph-field.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,38 @@
*
* 2. Update the variables to match your own field IDs.
*/
var streamFieldId = 1;
var promptFieldId = 2;
var responseFieldId = 3;
var streamFieldId = 3;
var promptFieldId = 1;
var responseFieldId = 4;
var appendButtonFieldId = responseFieldId;

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

$streamFieldInput.on( 'change', function() {
$( `#input_GFFORMID_${responseFieldId}` ).val( this.value );
$input = $( `#input_GFFORMID_${responseFieldId}` );
$input.val( this.value );
if (window.tinyMCE) {
var tiny = tinyMCE.get( $input.attr( 'id' ) );
if (tiny) {
tiny.setContent( this.value );
}
}
} );

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

$wpEditor = $newButton.parents( '.wp-editor-container' );
if ( $wpEditor.length ) {
$newButton.insertAfter( $wpEditor );
}

$( `#input_GFFORMID_${promptFieldId}` ).on( 'blur', function() {
$streamButton.trigger( 'click' );
} );

0 comments on commit c8f740f

Please sign in to comment.