Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Zendesk Filter Forms by Organization
// This will allow you to restrict forms by naming them with:
// Form-name-here [ONLY: Organization-name]
$(window).load(function() {
const formRegex = /\[ONLY: (\w+)]/;
function sanitizeForm(formName, orgs) {
result = {
formName: formName.replace(formRegex, ''),
allowed: false
}
if ((m = formRegex.exec(formName)) !== null) {
// form limitation
limitedOrg = m[1].toLowerCase();
orgs.forEach((orgEntry, index) => {
if ( orgEntry.name.toLowerCase() == limitedOrg ) {
result.allowed = true;
}
});
}
else {
// no limitation on that form
result.allowed = true;
}
return result;
}
var i = 0;
var checkExist = setInterval(function() {
i++;
if ($("a.nesty-input").length) {
clearInterval(checkExist);
$("a.nesty-input").each(function() {
$(this).bind("click", function() {
var forms = {}
var options = document.getElementById("request_issue_type_select").getElementsByTagName("option");
var formName;
for (i = 1; i < options.length; i++) {
formName = options[i].text;
formResult = sanitizeForm(formName, HelpCenter.user.organizations)
if ( formResult.allowed == false ) {
$('#' + options[i].value).remove();
}
else {
$('#' + options[i].value).html( formResult.formName );
}
};
});
});
}
if (i > 10) {
clearInterval(checkExist);
}
}, 100);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.