It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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

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

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

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

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

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>

 

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

Community showcase
Published in Confluence

2019: All Wrap(ped) Up Like a Present

Hindsight might be 2020 but looking back, a lot of cool new features rolled out in 2019. From new collaboration and organizational powers to fresh templates and handy integrations, it’s been quite th...

1,530 views 5 9
Read article

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