How to make custom field require on edit screen

Wu Yanfeng July 11, 2013

How to make custom field require on edit screen。

now my system is Jira6.0.1。

6 answers

2 accepted

3 votes
Answer accepted
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.
July 14, 2013

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>

Uday Karthik Yadlapalli October 27, 2014

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
Answer accepted
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 11, 2013

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

Wu Yanfeng July 12, 2013

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.

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 12, 2013

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.

Like fisnik kruja likes this
0 votes
Craig Leigh February 26, 2015

@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

0 votes
Wu Yanfeng July 14, 2013

Thanks

It works

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.
July 14, 2013

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

IshanL
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.
July 14, 2013

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

0 votes
IshanL
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.
July 11, 2013

Javascript is your savior :-)

Wu Yanfeng July 12, 2013

Thanks for your answer.

Can you give me same sample Javascript code.

Waiting for your response.

0 votes
IshanL
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.
July 11, 2013

Hi Wu,

you can make it required in Field Conriguration page,

e.g

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

Suggest an answer

Log in or Sign up to answer