How to make custom field require on edit screen

How to make custom field require on edit screen。

now my system is Jira6.0.1。

6 answers

1 accepted

Accepted Answer
3 votes

JavaScript to validate field on edit screen

<script type="text/javascript">
jQuery(document).ready(	function($) {
JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function(e,context) {
	callValidateFunction();
});	
callValidateFunction();
function callValidateFunction(){
	$('#edit-issue-submit, #issue-edit-submit').click(function() {
		var field=document.getElementById('customfield_13786');//chang customfield id 
		if(field !=null && field.value == ''){
		alert("Please Enter Field Value..")://change lert message as per your requirement
		return false;
		}
	
	});

}
});

</script>

Hello, do you have a JavaScript to make a system field Mandatory on Edit-screen. I am trying to make 'Comment' field mandatory whenever someone edits any issue. Thanks in Advance.

3 votes

You can't.

A field is either mandatory or optional. This is set by the field configuration for the project/issue-type and does not get any more granular. If a field is mandatory, it's mandatory on create, edit and all transitions. End of story, for Jira off-the-shelf.

Of course, there are options

You may add plugins that can add validators that work with optional fields, to enforce a user entering a field as an issue goes through transitions, but you can not add these to the "edit" function.

The standard workarounds boil down to:

Remove the field from "edit" and put in workflow transition where you can use validators

Use javascript or the behaviours plugin to enforce it

Hi Nic

Thanks for you answer.

But what I need is someone edit an issue must write edit reason, so that I need custom field required on "edit".

Set a field required on "Field Configrations", only validate create screen, even the required field is not on create screen, we can create issue sucessfully.

I'm afraid re-stating your question does not change the answer.

You can't put the validation on edit in the UI, you need to move it down into the workflow, or use javascript.

Hi Wu,

you can make it required in Field Conriguration page,

e.g

http://localhost:2990/jira/secure/admin/ViewIssueFields.jspa

Javascript is your savior :-)

Thanks for your answer.

Can you give me same sample Javascript code.

Waiting for your response.

Thanks

It works

if it is worked then dont forget mark it as corect answer/voteup :)

yes, It is good practice to mark correct answer and vote up

@Rambanam Prasad

I am new toJavascript, and thought I could use your code to solve a problem.  I have four fields cf_1, cf_2, cf_3, cf_4.  If any one or more (but not all yet) of the cf fields has a value, I want to display a message that all four fields need to be completed before updating from the edit screen.  

 

I used this variation of your script in the cf_1 field:

 

<script type="text/javascript">
jQuery(document).ready( function($) {
JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function(e,context) {
callValidateFunction();
});
callValidateFunction();
function callValidateFunction(){
var field=document.getElementById('customfield_13740');
var field1=document.getElementById('customfield_13741');
var field2=document.getElementById('customfield_13742');
var field3=document.getElementById('customfield_13743');
$('#edit-issue-submit, #issue-edit-submit').click(function() {
if((field !=null && field.value != '') && (field1.value == '' || field2.value == '' || field3.value == '') || (field1 !=null && field1.value != '') && (field.value == '' || field2.value == '' || field3.value == '') || (field2 !=null && field2.value != '') && (field.value == '' || field1.value == '' || field3.value == '') || (field3 !=null && field3.value != '') && (field.value == '' || field1.value == '' || field2.value == '')){
alert("If any escalation tab fields are completed then all must be..");
return false;
}
});
}
});
</script>

 

My script continues to loop displaying the message multiple times based on how many field are completed less than four.  Moreover using any browser I get this message also "Prevent this page from creating additional dialogues" checkbox.  Which if checked, I can never update the screen in further tests.  Any insight is greatly appreciated.

 

Thanks

--Craig Leigh

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

467 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