Making custom field text red?

How to make custom field text red?

<script type="text/javascript">
AJS.$("#customfield_11329").attr('style', 'color:red')
</script>

Above code does not work. Any ideas?

2 answers

1 accepted

2 votes
Accepted answer

In that way it does't work on 5+ jira version, try with this

&lt;script type="text/javascript"&gt;
jQuery(document).ready(function($) {
	JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function (e,context) {		
		callFunction();
	});
		callFunction();
	function callFunction(){  		AJS.$('label[for=customfield_11329]').css({color:'red'});
	}
});
&lt;/script&gt;

Great. It works!!

But only in edit screen, not in view screen.

glad to hear it worked!!

if it to be work on view screen you need to check custom field id on view screen

if my answer helped then vote up and accept as answerd :)

hello @Rambanam Prasad ,

Is there any idea how can I do it for edit too?

@Daniel Mor the above script will work on edit screen too, just you need to replace customfield id(you can get field id by inspecting element)

Thank you
@Rambanam Prasad,

This text has no id.. only "title" , and it id inside div that has id.. How can I write it in your code?

@Daniel Mor can you share html content of a customfield on edit screen?

try with this

AJS.$('label[for=customfield_11329]').css({'color':'red'});
or
AJS.$("#customfield_11329").parent('label').css('color','red');


Does not work!!!

<script type="text/javascript">
AJS.$("#customfield_11329").parent('label').css('color','red');
</script>

how you tried and whatis the jira version?

can you share your code? i tried now it is working

It is 5.1.5 version,

Still not working

@Rambanam Prasad In which file do I need to edit this?

@Joe Moreno you no need to edit any files, just add code in accepted Answer in Announcement banner for testing, once it worked as expected then i suggest to add this code as web resource module in a plugin(you will get lot of post on this forum if you need to know how to add it in plugin) Note: don't forgot to change customfield id :)

@Rambanam Prasad I have similar requirement where I need to change the mandatory field labels in Red. But here I am using ScriptRunner Behavior script and it is not working. Here is my code snippet.

// requiredFields has the list of mandatory fields labels.

for(String field in requiredFields){
field = field.trim()
log.warn("Field ::"+field)

String js = "<script type=\"text/javascript\">\n"+
"jQuery(document).ready(function(\$) {\n"+
"JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function (e,context) {\n"+
"callFunction();\n"+
"});\n"+
"callFunction();\n"+
"function callFunction(){\n"+
"AJS.\$('label[for="+field+"]').css({color:'red'});\n"+
"}\n"+
"});\n"+
"</script>"

log.warn(js)
def FormField f = getFieldByName(field)
f.setLabel(js)

Any help is highly appreciated.

<script type="text/javascript">
jQuery(document).ready(function($) {
JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function (e,context) {
callFunction();
});

callFunction();

function callFunction(){
AJS.$('label[for=customfield_11329]').css({color:'red'});
}
});
</script>

add above code on announcement banner by changing cusotmfield id

 

am not sure how to include javascript using behavior. 

@Rambanam Prasad Thank you. This works well for custom fields. Can this be possible for system fields? I want to show system fields also in Red.

yes, just you need to change replace customfield id with system field id

 

<script type="text/javascript">
jQuery(document).ready(function($) {
JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function (e,context) {
callFunction();
});

callFunction();

function callFunction(){
AJS.$('label[for=summary]').css({color:'red'});
AJS.$('label[for=components]').css({color:'red'});

}
});
</script>

@Rambanam Prasad Thank you!

It works...

@Rambanam Prasad  I have tried your script and its working fine. 

I have a custom field with "*" at the end of the label.  Is it possible to make only the "*" in Red color instead of whole text?

 

Thanks in Advance.

@Mani you need to try something like follows if you want to add red asterisk, if you have already asterisk and want to make red color then use CSS to make it red 

AJS.$("#customfield_11300").parent().children('label').append('<span class="aui-icon icon-required"></span>');

@Rambanam Prasad,

Thanks for your reply!

The script is working fine but custom field(version Picker(multiple versions) text is not changing to red color. Need total text to be in red color.

version.PNG

Tried with below script

<script type="text/javascript">
jQuery(document).ready(function($) {
JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function (e,context) {
callFunction();
});

callFunction();

function callFunction(){
AJS.$('label[for=customfield_11329]').css({color:'red'});
}
});
</script

can you share the HTML content for the custom field?

Hi @Rambanam Prasad,

 I don't see any option to get HTML content. It's a Version Picker(multiple version) custom field not default one.Capture123.PNG

@Rambanam Prasad,

HTML content for CMS TestVsersion/s field

<td id="custom-fields-customfield_11110-name">
<strong>CMS Test Version/s</strong>


<div class="secondary-text description">Specify the version(s) on which the defect has been tested.</div>
</td>
<td id="custom-fields-customfield_11110-type" class="nowrap">
Version Picker (multiple versions)
</td>
<td>

is the above code from create/transition screen?

I took HTML content from the web page.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Jan 08, 2019 in Jira

How to Jira for designers

I’m a designer on the Jira team. For a long time, I’ve fielded questions from other designers about how they should be using Jira Software with their design team. I’ve also heard feedback from other ...

1,294 views 5 10
Read article

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you