Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Make custom field read only on Jira Edit Screen using javascript

sbhutada
Contributor
January 14, 2019

I am trying to make a custom text field read-only on the edit screen of jira using javascript, but looks like below code is not working.

jQuery(document).ready(function($) {

JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function(e,context) {

var projectName = AJS.$("#project-name-val").text();
console.log("RFC projectName "+projectName);

if (projectName == "RT")
{
callReadonlyFunction();
}
}
});

function callReadonlyFunction(){
$('#edit-issue').click(function() {
           console.log("Edit Button Clicked Start");
           AJS.$("#customfield_13911").attr("readonly", true); //text field
           console.log("Edit Button Clicked End");
      });
}

 In the console log, I do see messages but for some reason, the field is not set to read-only.

1 answer

1 accepted

0 votes
Answer accepted
Nir Haimov
Community Champion
January 14, 2019

Why are you trying to do it with JS if you have Scriptrunner?

Go to "add-on" page and in the left panel you have "behaviours".

There you can determine a field with 3 options:

Required (Optional) 
Writable (Readonly) 
Shown (Hide)

So choose the "Writable (Readonly)" for your field.

Vineela Durbha
Contributor
October 13, 2020

@Nir Haimov 

I am even trying to set 'nfeed' field readonly through javascript during clone. ANy idea on how it can be done?

Nir Haimov
Community Champion
October 13, 2020

Hi @Vineela Durbha

I didn't understand what you said.

Vineela Durbha
Contributor
October 13, 2020

Hi @Nir Haimov 

On the announcement banner during clone operation , I am trying to set an "Element Connect " type of field to readonly.

JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function(e, context, reason) {

var isCloneIssuePage = AJS.$('#clone-issue-dialog').is(':visible');
var issuetype=AJS.$('#issue-create-issue-type').text();
if (isCloneIssuePage == true || AJS.$('#content .aui-page-header-main h1').text() == "Clone") {
alert('clone')
if(issuetype =="Customer Product SKU"){
alert(issuetype)

AJS.$('#customfield_15003').attr("readonly", true); //nfeed field

}

}

});

But the above code is not setting field to readonly

Nir Haimov
Community Champion
October 13, 2020

Hi @Vineela Durbha

I don't know what is an "Element Connect ".

Any way, when do you want to make the field read-only?

Clone is an action, where new issue created, do you want the field to be read only in the original issue, or cloned issue or both?

Vineela Durbha
Contributor
October 13, 2020

Hi @Nir Haimov 

I want to make field readonly during clone operation. ie, on clone screen i want the field to appear as readonly. I dont want to do anything for original issue. just make it readonly on cloned issue

Nir Haimov
Community Champion
October 14, 2020

Hi @Vineela Durbha

OK, Can you please send a screenshot of your clone screen and mark the field you want to make read-only?

Vineela Durbha
Contributor
October 14, 2020

@Nir Haimov 

Please find the screenshot below

Capture.PNG

Nir Haimov
Community Champion
October 14, 2020

Hi @Vineela Durbha

Are you using "Clone Plus for Jira" or any other plugin that extend the clone screen?

Because Jira by default don't allow you to set fields when clone, only the summary is changeable.

My point is, if you are using 3rd party plugin that extend the clone screen, my guess is that this plugin not fire the NEW_CONTENT_ADDED event, so your code block where you bind to this event JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function.... not gets executed (means, everything in the bind function not executed), did you try to debug and check if your function inside the bind works? does your code gets inside the bind?

Vineela Durbha
Contributor
October 14, 2020

Hi @Nir Haimov 

Yes we are using "Clone plus for JIra". Alerts inside JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function .. are working. I am getting both 'clone' and 'issuetype' alert values.

Nir Haimov
Community Champion
October 14, 2020

Hi @Vineela Durbha 

OK, so simply try to change this line:

AJS.$('#customfield_15003').attr("readonly", true); //nfeed field

to this:

AJS.$('#customfield_15003').attr("disabled", true); //nfeed field 
Vineela Durbha
Contributor
October 14, 2020

Hi @Nir Haimov 

Yes it worked. Thank you so much for your help :)

Suggest an answer

Log in or Sign up to answer