Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How to make a User Customfield Read Only through javascript on Create Screen?

Kapil Bolli
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.
May 13, 2013

Hi,

I want to make a user customfield readonly on Create Screen of JIRA 5.1.8.

When i am using customfied.disabled=true; Field has become Read-Only

Then on Creating issue, the value of that field is getting cleared.

So i have changed the script to :

AJS.$("#customfield_17802").attr("readonly", true);
		AJS.$("#customfield_17802").removeClass("editable-field inactive");
		AJS.$("#customfield_17802 .icon-edit-sml").remove();
		
		var div = document.getElementById("customfield_17802_container");
		var anchorList = div.getElementsByTagName('img');
		for(var i = 0; i < anchorList.length; i++) {
		anchorList[i].setAttribute('style','display:none');

}

With the above script , the field has become Readonly & image for selecting users is also removed.

But the user field is still suggesting(auto-complete feature) usernames which are similar to currently selected user.

ex: My user customfield is Current User Field.

I am logged in as user: jira , & user customfied is readonly .

but if there are user id's with jira1, jira2 & jira3 etc.

Then JIRA is suggesting the other values & user is able to select those values.

I don't want the user to select those values.

Thanks

Kapil

1 answer

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
RambanamP
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.
May 13, 2013

try with this

jQuery(document).ready(	function($) {
JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function(e,context) {
	//add your script here and try
});	
});

suggest you to load js as a webresource

https://developer.atlassian.com/display/JIRADEV/Web+Resource+Plugin+Module

Kapil Bolli
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.
May 13, 2013

Hi Rambanam,

I added the script with above Jquery , now the field is not happening to be ReadOnly.

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



	
		AJS.$("#customfield_17802").attr("readonly", true);
		AJS.$("#customfield_17802").removeClass("editable-field inactive");
		AJS.$("#customfield_17802 .icon-edit-sml").remove();
		
var div = document.getElementById("customfield_17802_container");

var anchorList = div.getElementsByTagName('img');
		for(var i = 0; i < anchorList.length; i++) {
		anchorList[i].setAttribute('style','display:none');}
		
		
	}); 
});   	
		
		</script>


-Kapil

Like Keith Shaw likes this
Eitzenberger Thomas February 9, 2017

to complete this make sure to also redirect any click event

AJS.$("#customfield_17802").on("click", funtion(e) { e.stopPropagation(); e.preventDefault(); return false});

Like Keith Shaw likes this
Keith Shaw December 14, 2018

This is great !

UPDATE - After I refined some things
This will insert whatever value you wish and grey out / disable input
You can isolate this to a specific form using unique field configurations.
Just insert this into the description box. 
If you still want a note to appear just add it after the script.


<script type="text/javascript">
if (document.getElementById("summary").value == "") {
document.getElementById("summary").value = "Address Change Request for\n";}
{document.getElementById("summary").disabled= true;}
</script>

 
I tried to hide the box and the entire summary block but ran into issues with the word "Summary" before the box.

<script type="text/javascript">
if (document.getElementById("summary").value == "") {
document.getElementById("summary").value = "Address Change Request for\n";}
{document.getElementById("summary").disabled= true;}
{document.getElementById("summary").style.visibility = "hidden";}
{document.getElementByid("qf-field-summary").display = "none";}
</script>

 

Keith Shaw December 14, 2018

I am sorry to report that JIRA is a pain in the ... 
Once you attempt to Create the ticket it all comes crumbling down.
If anyone knows how to "trick" that validation into working that would be great.

Snap 2018-12-14 at 12.38.20.jpg

TAGS
AUG Leaders

Atlassian Community Events