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 edited

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
TAGS
atlassian, mindful member, mindful member badge, atlassian community, community kudos, community giveaway, atlassian swag, community values, empathy and kindness, badge challenge, atlassian learning, community engagement, swag giveaway

Earn a Badge, Win a Prize 🎁

Earning the Mindful Member badge proves you know how to lead with kindness, plus it enters you into a giveaway for exclusive Atlassian swag. Take the quiz, grab the badge, and comment on our announcement article to spread the good vibes!

Start here
AUG Leaders

Atlassian Community Events