We need to hide a certain field namely "Specify the reason of Critical Priority" (Custom Field value 10112 ) based on Priority field value. We need to show this only when Priority Value is "Critical"
We have write java script in "Specify the reason of Critical Priority" field's description to meet this expectation. Please find the javasripr below -
<script type="text/javascript"> priority = document.getElementById('priority'); if (priority) { target = document.getElementById('customfield_10112'); // Hide the target field if priority isn't critical if (priority.value != 2) target.style.display='none'; priority.onchange=function() { if (this.value == 2) { target.style.display = ''; target.value="enter message here"; } else { target.style.display='none'; } } } </script>
After configuring by above mentioned procedure "Specify the reason of Critical Priority" field is showing only when "Critical" priority is selected. When "Critical" Priority is not selected this field is not showing alright but "Specify the reason of Critical Priority" Custom Field name is showing everytime. Means Field is hideing but fieldname is showing. Could you please suggest regarding this?
Hi Prasad,
Thank you very much for your help. Right now Show/Hide Customfield based on Priority field value working perfectly. I have not use alert(selectedPriority) .I have used below mentioned code and it's working perfectly after clearing the browser cache -
jQuery(document).ready(function($) { JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function (e,context) { showHideFieldFunction(); }); showHideFieldFunction(); function showHideFieldFunction(){ showHideField(); $('#priority').change(function() { showHideField(); }); } function showHideField(){ var selectedPriority=$("#priority").val(); if(selectedPriority == '2'){ $('#customfield_10112').closest('div.field-group').show(); }else{ $('#customfield_10112').closest('div.field-group').hide(); } } });
if my answer's helped then don't forgot to accept as a answer :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
click on tick mark on left side of the user inmage, check this on following immage
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
my answers also accept a answers right?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
you need to click on tick mark which is left side of the user image
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
so was the problem the browser cache, been following this thread trying to figure out what was the initial problem with the initial code. if u use your first code and clear cache does it work
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Chris,
It did work when I used below mentioned code and clear the browser cache -
jQuery(document).ready(function($) { JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function (e,context) { showHideFieldFunction(); }); showHideFieldFunction(); function showHideFieldFunction(){ showHideField(); $('#priority').change(function() { showHideField(); }); } function showHideField(){ var selectedPriority=$("#priority").val(); if(selectedPriority == '2'){ $('#customfield_10112').closest('div.field-group').show(); }else{ $('#customfield_10112').closest('div.field-group').hide(); } } });
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Still problem not resolved. Right now required field not showing even choosing Critical Priority. Please find the updated javascript below -
jQuery(document).ready(function($) { JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function (e,context) { showHideFieldFunction(); }); showHideFieldFunction(); function showHideFieldFunction(){ showHideField(); $('#priority').change(function() { showHideField(); }); } function showHideField(){ var selectedPriority=$("#priority").val(); if(selectedPriority == '2'){ $('#customfield_10112').closest('div.field-group').show(); }else{ $('#customfield_10112').closest('div.field-group').hide(); } } });
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
give following alert after 15th line
alert(selectedPriority);
remove browser cache and try!! it should work!
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.
Hi Prasad,
Actually there is a spelling mistake in my code. After correcting the code plugin build successfully. But after uploading this plugin in Jira problem remain same. Could you please look into this
Regards
Sumit
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
priority field is a syatem field and options are 1,2,...,5, so you have to replace "Critical" with correct value
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Prasad,
I have put the Critical value in my javascript and build the plugin again. But problem still remain same. Right now required field not showing even selecting 'Critical' from Priority field. Please find my recent code below and inform there is any problem -
jQuery(document).ready(function($) { JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function (e,context) { showHideFieldFunction(); }); showHideFieldFunction(); function showHideFieldFunction(){ showHideField(); $('#priority').change(function() { showHideField(); }); } function showHideField(){ var selectedPriority=$("#priority option:selected").text(); if(selectedPriority == '2'){ $('#customfield_10112').closest('div.field-group').show(); }else{ $('#customfield_10112').closest('div.field-group').hide(); } } });
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
replace no 15 line with this
var selectedPriority=$('#priority').val();
and also give alerts and check wheather this script executing or not
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
try with this javascript if you are using jira 5.x, make sure customfield id and priority selected value is correct(casesensitive)
<script type="text/javascript"> jQuery(document).ready(function($) { JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function (e,context) { showHideFieldFunction(); }); showHideFieldFunction(); function showHideFieldFunction(){ showHideField(); $('#priority').change(function() { showHideField(); }); } function showHideField(){ var selectedPriority=$("#priority option:selected").text(); if(selectedPriority == 'Critical'){ $('#customfield_10112').closest('div.field-group').show(); }esle{ $('#customfield_10112').closest('div.field-group').hide(); } } }); </script>
if this function need call it on create screen then i suggest to load it as a webresource module in a plugin rather than adding n description
check this
https://answers.atlassian.com/questions/47843/strange-javascript-problem-in-create-screen
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Prasad,
Thank you for your reply. I am using websource module for this purpose. In that case I am writing below mentioned script in JS file for build plugin. Please find the sript below -
jQuery(document).ready(function($) { JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function (e,context) { showHideFieldFunction(); }); showHideFieldFunction(); function showHideFieldFunction(){ showHideField(); $('#priority').change(function() { showHideField(); }); } function showHideField(){ var selectedPriority=$("#priority option:selected").text(); if(selectedPriority == 'Critical'){ $('#customfield_10112').closest('div.field-group').show(); }esle{ $('#customfield_10112').closest('div.field-group').hide(); } } });
But after that when we try to create the plugin using atlas-package following error showing -
org.mozilla.javascript.EvaluatorException: Compilation produced 3 syntax errors.
Could you please confirm wheather I am putting right code in js file or not ? The values of this script is correct
Regards
Sumit
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
the above code looking good, can you share some more log message
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Please find the complete error -
[INFO] Trace org.mozilla.javascript.EvaluatorException: Compilation produced 3 syntax errors. at com.atlassian.maven.plugins.amps.util.minifier.YUIErrorReporter.runti meError(YUIErrorReporter.java:35) at org.mozilla.javascript.Parser.parse(Parser.java:392) at org.mozilla.javascript.Parser.parse(Parser.java:337) at com.yahoo.platform.yui.compressor.JavaScriptCompressor.parse(JavaScri ptCompressor.java:312) at com.yahoo.platform.yui.compressor.JavaScriptCompressor.<init>(JavaScr iptCompressor.java:533) at com.atlassian.maven.plugins.amps.util.minifier.ResourcesMinifier.yuiJ sCompile(ResourcesMinifier.java:228) at com.atlassian.maven.plugins.amps.util.minifier.ResourcesMinifier.proc essJs(ResourcesMinifier.java:164) at com.atlassian.maven.plugins.amps.util.minifier.ResourcesMinifier.proc essResource(ResourcesMinifier.java:61) at com.atlassian.maven.plugins.amps.util.minifier.ResourcesMinifier.mini fy(ResourcesMinifier.java:40) at com.atlassian.maven.plugins.amps.MavenGoals.compressResources(MavenGo als.java:504) at com.atlassian.maven.plugins.amps.CompressResourcesMojo.execute(Compre ssResourcesMojo.java:33) at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPlugi nManager.java:483) at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(Defa ultLifecycleExecutor.java:678) at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalWithLi fecycle(DefaultLifecycleExecutor.java:540) at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(Defau ltLifecycleExecutor.java:519) at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHan dleFailures(DefaultLifecycleExecutor.java:371) at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegmen ts(DefaultLifecycleExecutor.java:332) at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLi fecycleExecutor.java:181) at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:356) at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:137) at org.apache.maven.cli.MavenCli.main(MavenCli.java:356) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl. java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces sorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315) at org.codehaus.classworlds.Launcher.launch(Launcher.java:255) at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430) at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi ,
It would probably be something like this :
<script type="text/javascript"> priority = document.getElementById('priority'); if (priority) { target = document.getElementById('customfield_10112'); label = document.getElementById('Specify the reason of Critical Priority'); // Hide the target field if priority isn't critical if (priority.value != 2){ target.style.display='none'; label.style.display='none'; } priority.onchange=function() { if (this.value == 2) { target.style.display = ''; label.style.display=''; target.value="enter message here"; } else { target.style.display='none'; label.style.display='none'; } } } </script>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Sumit,
I'm sorry but I'm not really a Javascript expert, I think the my reasoning is sound (you also need to hide the label element when the priority is != 2) but I don't know exactly how to do this with javascript (especially not when I can't test it)
Best regards,
Peter
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
You'll probably need to look at the ElementId of the custom field label and set the target.style.display= 'none' for it too.
Best regards,
Peter
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Peter,
Could you please elaborate. I am not clear. Could you please modify my above mentioned javascript and send to me. It will be more helpful for me.
Thanks for your Reply
Regards
Sumit
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.