Skip to content

Instantly share code, notes, and snippets.

@Sarapulov
Created January 2, 2017 15:37
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sarapulov/fa9ff73c347c141472ea134b7bef54d1 to your computer and use it in GitHub Desktop.
Save Sarapulov/fa9ff73c347c141472ea134b7bef54d1 to your computer and use it in GitHub Desktop.
Preset given nested dropdown on Zendesk Help Center with a given value
/**
* Preset given nested dropdown on Zendesk Help Center with a given value
*
* @param {String} field_id (example: 'request_custom_fields_31265065')
* @param {String} field_value (example: 'complaint_type_b')
*/
function presetNestedDrodown(field_id,field_value){
if (!field_id || field_value === undefined) return;
var $field = $('.'+field_id);
if ($field && $field.length > 0 && $field.hasClass('string')) {
var $input = $field.find('input'), $d = $input.attr('data-tagger');
$d && JSON.parse($d).forEach(function(obj){
if (obj.value === field_value) $input.val(obj.value).closest('.nesty-input').text(obj.label);
});
}
}
presetNestedDrodown('request_custom_fields_23496063','corolla');
// presetNestedDrodown('request_custom_fields_23530886','accord');
// presetNestedDrodown('request_custom_fields_23502577','blahhhh');
// presetNestedDrodown('request_custom_fields_23506078','toyota_ncr');
// presetNestedDrodown('request_custom_fields_31265065','complaint_type_b');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment