Show - hide jira custom field select list options troubleshooting?

Hi everybody,

i have created a .js for show - hide the options of a select list. The problem that i have is that .hide() and .show() works only for Firefox.

The .js i have is the following

jQuery("#customfield_12300").change(function() {
       
		if (jQuery("#customfield_12300").val() == '11400') {
			//Unselect all values on change event
			jQuery("#customfield_12302").val([]);
			//Hide Pending Reasons that do not match the type of account
			
			jQuery("#customfield_12302").children("option[value='11402']").hide();
			
			jQuery("#customfield_12302").children("option[value='11404']").hide();
			
			jQuery("#customfield_12302").children("option[value='11505']").hide();
			
			jQuery("#customfield_12302").children("option[value='11506']").hide();
			
			jQuery("#customfield_12302").children("option[value='11507']").hide();
			
			jQuery("#customfield_12302").children("option[value='11508']").hide();
			
			jQuery("#customfield_12302").children("option[value='11509']").hide();
			
			//Show pending reasons that match the type of account
			
			jQuery("#customfield_12302").children("option[value='11510']").show();
			
			jQuery("#customfield_12302").children("option[value='11511']").show();
			
			jQuery("#customfield_12302").children("option[value='11512']").show();
			
			jQuery("#customfield_12302").children("option[value='11513']").show();
			
			jQuery("#customfield_12302").children("option[value='11514']").show();
			
			
			
		} else if (jQuery("#customfield_12300").val() == '11401'){
			
			jQuery("#customfield_12302").val([]);
			//Hide Pending Reasons that do not match the type of account
			
			jQuery("#customfield_12302").children("option[value='11510']").hide();
			
			jQuery("#customfield_12302").children("option[value='11511']").hide();
			
			jQuery("#customfield_12302").children("option[value='11512']").hide();
			
			jQuery("#customfield_12302").children("option[value='11513']").hide();
			
			jQuery("#customfield_12302").children("option[value='11514']").hide();
			
			//Show pending reasons that match the type of account
			
			jQuery("#customfield_12302").children("option[value='11402']").show();
			
			jQuery("#customfield_12302").children("option[value='11404']").show();
			
			jQuery("#customfield_12302").children("option[value='11505']").show();
			
			jQuery("#customfield_12302").children("option[value='11506']").show();
			
			jQuery("#customfield_12302").children("option[value='11507']").show();
			
			jQuery("#customfield_12302").children("option[value='11508']").show();
			
			jQuery("#customfield_12302").children("option[value='11509']").show();
			
		}
	});

Here is the html code for the list with the options i want to control

<div class="field-group">
                                                                        <label for="customfield_12302">Pending Reasons<span class="aui-icon icon-required">Required</span></label>
                <select class="select" id="customfield_12302" multiple="multiple" name="customfield_12302" size="5">
                            <option value="11402" style="display: none; ">
                Option 1
            </option>
                                <option value="11404" style="display: none; ">
                Option 2
            </option>
                                <option value="11403">
                Option 3
            </option>
                                <option value="11405">
                Option 4
            </option>
                                <option value="11500">
                Option 5
            </option>
                                <option value="11501">
               Option 6
            </option>
                                <option value="11502">
                Option 7
            </option>
                                <option value="11503">
                Option 8
            </option>
                                <option value="11504">
                Option 9
            </option>
                                <option value="11511">
                Option 10
            </option>
                                <option value="11510">
                Option 11
            </option>
                                <option value="11512">
                Option 12
            </option>
                                <option value="11505" style="display: none; ">
                Option 13
            </option>
                                <option value="11506" style="display: none; ">
                Option 14
            </option>
                                <option value="11507" style="display: none; ">
                Option 15
            </option>
                                <option value="11508" style="display: none; ">
                Option 16
            </option>
                                <option value="11509" style="display: none; ">
                Option 17
            </option>
                                <option value="11513">
                Option 19
            </option>
                                <option value="11514">
                Option 20
            </option>
            </select>
                                       <div class="description">Ctrl+Click to choose multiple values</div>

</div>

From things i have seen .show() and .hide() are not available for Chrome.

A workaround was to use .detach() and .append() but that breaks the order of options in select list.

Any ideas how to make it work for the majority of browsers?

Thanks in advance,

Kostas

3 answers

$("#customfield_id option[value='1']").attr('disabled','disabled') //to disable
$("#customfield_id option[value='a']").attr('disabled','') //to ENABLE

try with the above code

Well, I'm not having luck with .hide on Chrome, so this will do for now. Thanks!!

Hi Kostas,

can you provide your HTML Code as well? I'm sure there is a much more elegant method to achieve what you want.

Regards,
Felix

Hey Felix,

the .js file is part of a plugin. Plugin has a web resource module. That's how it looks the web resource module in atlassian-plugin.xml

&lt;web-resource key="test-js" name="javascript"&gt;
        &lt;dependency&gt;jira.webresources:global-static&lt;/dependency&gt;
        &lt;description&gt;JavaScript&lt;/description&gt;
        &lt;resource name="test.js" type="download" location="/js/test.js" /&gt;
        &lt;context&gt;atl.general&lt;/context&gt;
    &lt;/web-resource&gt;

test.js is the code i have in question's body.
Hope that helps.
Cheers,
Kostas

I have added the html part of the custom field in question's body.

Hi Tsol,

Try the following code, Please dont hide and show each and every children, instead do the following,

jQuery($("#customfield_11111")).change(function() { 
          // will clearout all the values in the select list
          $("#customfield_13683").html('');
          showorhide(inputvalue);
});

function showorhide(inputvalue){
   // start appending the values based on the input value  //use if else
     if(condition based on inputvalue){
          $("#customfield_13683").append('&lt;option value="-1"&gt;None&lt;/option&gt;');
      }
}

Hope this Helps.

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Julia Dillon
Posted Tuesday in Jira

Tell us how your team runs on Jira!

Hey Atlassian Community! Today we are launching a bunch of customer stories about the amazing work teams, like Dropbox and Twilio, are doing with Jira. You can check out the stories here. The thi...

158 views 1 17
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