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

Accepted Answer
2 votes

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 :)

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 :)

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

@RambanamP 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>

@RambanamP Thank you!

It works...

@RambanamP  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>');

@RambanamP,

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 @RambanamP,

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

@RambanamP,

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
Posted Sep 25, 2018 in Jira

Atlassian Research Workshop opportunity on Sep. 28th in Austin, TX

We're looking for participants for a workshop at Atlassian! We need Jira admins who have interesting custom workflows, issue views, or boards. Think you have a story to sha...

449 views 7 5
Join discussion

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