Last active
August 29, 2015 14:08
-
-
Save skipjac/f509ac2701bab9d10a83 to your computer and use it in GitHub Desktop.
This changes the not selected label in zendesk helpcenter
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
//this function will walk all the way down the JSON object into all the arrays and create flat JSON object. | |
function flattenObject(ob) { | |
var toReturn = {}; | |
for (var i in ob) { | |
if (!ob.hasOwnProperty(i)) continue; | |
if ((typeof ob[i]) == 'object' && ob[i] !== null) { | |
var flatObject = flattenObject(ob[i]); | |
for (var x in flatObject) { | |
if (!flatObject.hasOwnProperty(x)) continue; | |
toReturn[i + '.' + x] = flatObject[x]; | |
} | |
} else { | |
toReturn[i] = ob[i]; | |
} | |
} | |
return toReturn; | |
} | |
// this function goes through the listOfDefaults object and searches for each default value in the listed ticket field | |
function setDefaultVaule(field, setDefault){ | |
$('.request_custom_fields_' + field).one('DOMNodeInserted', function(d){ | |
var inputTar = $(d.currentTarget).children('input') | |
var TestObj = inputTar.data('tagger'); | |
var test = flattenObject(TestObj); | |
var myRe = /value$/g; | |
for (var key in test) { | |
var isValue = myRe.test(key); | |
if (isValue && test[key] === setDefault) { | |
$(inputTar).attr('value', test[key]); | |
$(d.target).text('Please Selection a option'); | |
return; | |
} else { | |
var label = test[key]; | |
} | |
} | |
}); | |
} | |
//build a JSON object with the ticket field ID as the key to the default tag value you want to set | |
var listOfDefaults = { '22103126' : '', '21631456': ''}; | |
$(document).ready(function(){ | |
for(var key in listOfDefaults){ | |
setDefaultVaule(key, listOfDefaults[key]); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment