Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save shenoyranjith/7a6e48cdb8030da573d936b6b64c3749 to your computer and use it in GitHub Desktop.
Save shenoyranjith/7a6e48cdb8030da573d936b6b64c3749 to your computer and use it in GitHub Desktop.
Zendesk Nesty input customization
// Remove the option from the select element
$('#<complete_zendesk_form_field_id> option[value="<zendesk_dropdown_value_tag>"]').remove();
// Callback function to execute when mutations are observed
const callback = function(mutationsList, observer) {
for(let mutation of mutationsList) {
if (mutation.type === 'childList') {
// Remove the option from the nesty-input after it's been created
$('.nesty-panel').children('ul').children().remove('#<zendesk_dropdown_value_tag>');
}
}
};
const buildingFieldEle = document.querySelector('.request_custom_fields_21512039916189');
const buildingNestyInput = buildingFieldEle.querySelector('a.nesty-input');
const buildingNestyInputPanel = document.querySelector(`.nesty-panel#${buildingNestyInput.getAttribute('aria-controls')}`);
let panelOpen = false;
// Callback function to execute when mutations are observed
const callback = function(mutationsList, observer) {
for(let mutation of mutationsList) {
if (mutation.type === 'childList') {
if(!panelOpen) {
const elementToSelect = $('.nesty-panel').children('ul').children('li.nesty-expand')[0];
if((!mutation.previousSibling && !mutation.removedNodes.length ) && elementToSelect && !panelOpen) {
elementToSelect.click();
panelOpen = true;
}
}
else if (mutation.removedNodes.length > 0 && !mutation.target.querySelector('ul')) {
panelOpen = false;
}
}
}
};
// Create an observer instance linked to the callback function
const observer = new MutationObserver(callback);
// Start observing the target node for configured mutations
observer.observe(buildingNestyInputPanel, { childList: true });
@shenoyranjith
Copy link
Author

for nested fields first get all the nest panels

var skip1 = document.querySelectorAll('.nesty-panel')

Then watch for every time the panel is inserted to the DOM and remove the options by tag you don't need

$(skip1).on('DOMNodeInserted', function(e){$(this).children('ul').children().remove('#nest__two_2');})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment