Hide an option in a custom dropdown field from end user on request form | Community
Skip to main content

Hide an option in a custom dropdown field from end user on request form

  • September 8, 2016
  • 6 replies
  • 0 views

I'd like to have some of the options in a custom dropdown field hidden from the end user when they submit a new ticket. The end user must first select a form and then the topic related to the form (this is the dropdown field). Because some of those options are not appropriate for an end user I'd like them hidden. The hidden options would be displayed for the agent when they work the ticket or create a new one.

I've been doing research on multiple support documents and found one (https://support.zendesk.com/hc/en-us/articles/218035948) that said the language could be hidden in the language dropdown. Here's the snippit:

Hiding a language in the language selector can be useful if the content in that language isn't ready for release. Add the following jQuery statement to the $(document).ready(function() function in the JavaScript template:

$("ul.dropdown-panel li a:contains('Français')").hide();

I'd like to do something similar but I think I also have to base the hide logic on which Form the end user selected.

I also found another support document (https://support.zendesk.com/hc/en-us/community/posts/203457426-Conditional-dropdown-field-sample-Conditions-based-on-tags-Web-portal-) that spoke to hiding dropdown options based on the organization. Here's the snippit:

Initial case.
1. You have a two groups of custumers organizations. Enterprise organizations tagged by "enterprise". Small organizations tagged by "small"

You have a dropdown field "Type of service" with items
a. Ticket support (tagged as "ticket_support")
b. Request for change (tagged as "request_for_change")
c. Personal consultation (tagged as "personal_consultation")
d. Fix bug in place (tagged as "in_place")
And you want to hide c. and d. items from dropdown for organization tagged by "small"

The problem with the second piece of logic is that it's written for the HTML code on the New Request page. I'd like to create the logic to be added to the jQuery section of the Help Center. 

I'd also need to base the logic on the Form selected.

We are using the Conditional Fields app to dynamically display fields on the new request page for an end user but I can't control individual options on a dropdown menu with that app. 

Can someone suggest a solution?

6 replies

  • Author
  • September 15, 2016

I really didn't receive much help other than a suggestion to read a support doc or to contact support for custom code.

Instead I reached out to our own IT team and we came up with a very simple, elegant solution! I think I might post this elsewhere on your site so others could replicate if they have a similar use case.

Wonder if Zendesk might also think about adding this function as part of your out-of-the-box solution? It's really helpful to have only one topic list (instead of an internal and external) displayed after the Form is selected.

The following simple code needs to be added on the JS page under 

$(document).ready(function() {
 

1) Create a variable to store the tags of options that we want to hide from end-users. Multiple tags can be added with a comma separation.

var tagsToRemove = ['manually_canceled'];

2) Execute logic to remove the options:

removeTagsWeDontWant();

3) Here's the code added at the end of the JS page:

function removeTagsWeDontWant() {
$('.nesty-panel').on('DOMNodeInserted', function(e){
for(var i in tagsToRemove) {
$('li#' + tagsToRemove[i]).remove();
}
});

}


  • Community Manager
  • September 15, 2016

Glad to hear you found a solution, Bonnie, and thanks for sharing! I'd definitely encourage you to share this for others to use. 


  • May 11, 2018

Hi!

I would like to hide some options from a custom drop down field from end users. I tried to edit the code but I could not find the $(document).ready(function() since we are using a custom theme. 

May I know where else I can edit it instead?

Thanks! 


  • July 15, 2020

Hi @Bonnie Schofield , im stuck in a similar problem and your solution doesn't work anymore i think that's because you are using "li" and the dropdowns values are now created as a div?

What im trying to achieve is i have a ticket field dropdown that is editable for end users. I would like to remove and rename some of drop down values for end users. So agents would see all of those in the tickets but end-users would see only some of them. Can you assist me with this?

Update : i was able to achieve removing of options but whenever i try to rename it within the same code block the form gets stuck

$('.nesty-panel').on('DOMNodeInserted', function(e){

for(var i in tagsToRemove) {
$(this).children('ul').children().remove('#' +tagsToRemove[i]);
}

$('#ID').text('new_value');

)};


Brett13
  • Community Manager
  • August 13, 2020

Hey Jessie,

It looks like you haven't received a response on this post. We're you able to get your code working at all? If so, any chance you could share what the fix was as I'm sure others have run into a similar issue.

Hope to hear from you soon!


  • September 27, 2020

I had a requirement to hide a certain option in a custom dropdown ticket field if the user is not in specific groups. The code below worked for me, in script.js inside the document ready function. Note that this code is being used in a templating API v1 theme. I believe the jquery would need to be converted to javascript for it to work in a templating API v2 theme.

const ITGroups = ['group-name-1', 'group-name-2'];

function isUserInGroups(groups) {
    var groupsMatched = HelpCenter.user.groups.filter (function(group) {
        return groups.includes(group.name);
    });
    return groupsMatched.length > 0;
}

if (!isUserInGroups(ITGroups)) {
    $('.nesty-input').on('click', function() {
        $('#tag-associated-with-option').remove();
    });
}

You can find the tag associated with the option by navigating to ticket fields in the agent dashboard, selecting the ticket field, and then clicking Show tags.