Show - hide jira custom field select list options troubleshooting?

Tsol
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.
January 31, 2013

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

1 vote
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.
March 18, 2013
$("#customfield_id option[value='1']").attr('disabled','disabled') //to disable
$("#customfield_id option[value='a']").attr('disabled','') //to ENABLE

try with the above code

Darryl Lee November 21, 2013

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

0 votes
Nitram
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.
March 18, 2013

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.

0 votes
Felix Grund (Scandio)
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.
January 31, 2013

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

Tsol
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.
January 31, 2013

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

Tsol
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.
January 31, 2013

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

Suggest an answer

Log in or Sign up to answer