Forums

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

How to render contents of text field in a specific color

Amir Katz (Outseer)
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 21, 2018

I have a multi-line text field (optional). I would like the text (when there is text) to be in displayed in red, which means to surround it with [color:red] <text here> [color] (using square brackets here to avoid rendering :-))

I can probably hack a behaviour that will edit the field value when field changes, but it's really a hack.

Any idea? Any existing solution?

Thanks

1 answer

0 votes
Alexey Matveev
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 21, 2018

Hello,

You can use Java Script for it. But it is not a mantainable solution. Or have a look at plugins. For example, like:

https://marketplace.atlassian.com/apps/1211608/color-custom-fields?hosting=server&tab=overview

Amir Katz (Outseer)
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 26, 2018

The plugin above does not do what I need...

The solution I see is to add a ScriptRunner Behaviour on the field and whenever it changes, add the color coding around it. A really ugly solution...

Alexey Matveev
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 26, 2018

You can not add a colour coding, using ScriptRunner behaviours.

Amir Katz (Outseer)
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 26, 2018

Thanks @Alexey Matveev If I modify the field in a Behaviour, it might trigger the Behaviour again and then will go into an infinite loop...is that what you mean?

Alexey Matveev
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 26, 2018

No, I mean that there is no methods in behaviour to change a colour for a field.

Amir Katz (Outseer)
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 26, 2018

I can always set the field value with 

def newValue = "{color:red}" + oldFieldValue + "{color}"
customFieldObj.setFormValue(newValue)
Like Aynur likes this
Alexey Matveev
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 26, 2018

Did you try it? It does not set a colour. 

Amir Katz (Outseer)
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 26, 2018

You need to change the field text renderer to Wiki Style Renderer and then it works. You do that in the field configuration.

Alexey Matveev
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 26, 2018

Ok. If it works for you, then you can do it:)

Joe Harmon
Contributor
August 28, 2019

Amir, I have server so I can set the renderer.  Is it possible to do something like if the value of the field is >= 0 then green, if it is <0 then red? Do you have an example you can give me?  Also, where do you put this code?

Amir Katz (Outseer)
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 29, 2019

It sounds complicated and you must have ScriptRunner. Also, since it's a long text field, it does not have a single integer value.

What you ca do is this:

  1. Create a behaviour on the field
  2. In the behaviour, read the new field contents
  3. Strip away all wiki-style formatting (which may be there if the user just modified the field)
  4. Set new formatting based on some criteria applied against the text 
Like Aynur likes this
Aynur May 10, 2022

Thanks a lot Amir, it works for me.

 

For more detailed information, have a look this link https://jira.atlassian.com/secure/WikiRendererHelpAction.jspa?section=all

Suggest an answer

Log in or Sign up to answer