Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,300,104
Community Members
 
Community Events
165
Community Groups

How to render contents of text field in a specific color

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

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

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...

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

Thanks @Alexey Matveev _Appfire_ 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?

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

I can always set the field value with 

def newValue = "{color:red}" + oldFieldValue + "{color}"
customFieldObj.setFormValue(newValue)
Like Aynur likes this

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

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

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

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?

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

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
TAGS

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you