Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Script to add info rich text editor fields and comment

Alex Trebek
Contributor
February 14, 2023

Hello!

I'm trying to use javascript to append text in rich text editor fields.

It works as expected in Description field with

AJS.$("#description").val(AJS.$("#description").val() + " new *formatted* text");

 

But the same trick doesn't work in Comment field.

Nothing happens if you call:

AJS.$("#comment").val(AJS.$("#comment").val() + " new *formatted* text")

Although, if you run AJS.$("#comment").val(), then console returns expected value. But it does not appear on screen and it's not being added as a comment if submitted.

 

By fiddling around in console, I found that this way it almost works:

AJS.$("textarea#comment.textarea.long-field.wiki-textfield.mentionable.wiki-editor-initialised").val(AJS.$("textarea#comment.textarea.long-field.wiki-textfield.mentionable.wiki-editor-initialised").val() + " new *formatted* text");

Added text appears in Comment field.

But if you change anything manually in comment field and run command once again, all manually applied changes are being deleted and the script just adds scripted text to "previous" state of the field.

 

 

Has anybody encountered this problem?

Is there any other way to adjust text in Comment field on browser side?

1 answer

1 accepted

1 vote
Answer accepted
Alex Trebek
Contributor
February 14, 2023

Figured it out.

Even more specific reference works:

AJS.$("textarea#comment.textarea.long-field.wiki-textfield.mentionable.wiki-editor-initialised.wiki-edit-wrapped.richeditor-cover").val(AJS.$("textarea#comment.textarea.long-field.wiki-textfield.mentionable.wiki-editor-initialised.wiki-edit-wrapped.richeditor-cover").val() + " new *formatted* text");

Suggest an answer

Log in or Sign up to answer