Skip to content

Commit ff20239

Browse files
authored
gcoai-stream-to-paragraph-field.js: Fixed duplicate code and an issue where output wouldn't copy to a plain text Paragraph field if any rich text Paragraph fields existed on the form.
1 parent e152f52 commit ff20239

File tree

1 file changed

+7
-16
lines changed

1 file changed

+7
-16
lines changed

gc-openai/gcoai-stream-to-paragraph-field.js

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@ $streamFieldInput.on( 'change', function() {
2727
$input = $( `#input_GFFORMID_${responseFieldId}` );
2828
var inputValue = this.value;
2929

30-
// Get HTML from response field if TinyMCE is available.
31-
if (window.tinyMCE) {
32-
var html = $streamFieldInput.closest( '.gfield' ).find('.gcoai-output').html();
30+
// Check if the response field has TinyMCE enabled.
31+
var tiny = window.tinyMCE && tinyMCE.get( $input.attr( 'id' ) );
3332

33+
// Get HTML for the response field if TinyMCE is available.
34+
if (tiny) {
35+
var html = $streamFieldInput.closest( '.gfield' ).find('.gcoai-output').html();
36+
3437
// Set HTML content in TinyMCE.
35-
var tiny = tinyMCE.get( $input.attr( 'id' ) );
36-
if (tiny) {
37-
tiny.setContent( html );
38-
}
38+
tiny.setContent( html );
3939
} else {
4040
// If TinyMCE is not available, use plain text.
4141
$input.val( inputValue );
@@ -57,13 +57,4 @@ if ( $wpEditor.length ) {
5757

5858
$( `#input_GFFORMID_${promptFieldId}` ).on( 'blur', function() {
5959
$streamButton.trigger( 'click' );
60-
} );
61-
62-
$wpEditor = $newButton.parents('.wp-editor-container');
63-
if ($wpEditor.length) {
64-
$newButton.insertAfter($wpEditor);
65-
}
66-
67-
$( `#input_GFFORMID_${promptFieldId}` ).on('blur', function() {
68-
$streamButton.trigger('click');
6960
});

0 commit comments

Comments
 (0)