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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
if it is worked then dont forget mark it as corect answer/voteup :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
yes, It is good practice to mark correct answer and vote up
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Javascript is your savior :-)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for your answer.
Can you give me same sample Javascript code.
Waiting for your response.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Wu,
you can make it required in Field Conriguration page,
e.g
http://localhost:2990/jira/secure/admin/ViewIssueFields.jspa
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.