-
-
Save shenoyranjith/7a6e48cdb8030da573d936b6b64c3749 to your computer and use it in GitHub Desktop.
Zendesk Nesty input customization
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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');})