Last active
October 12, 2016 12:59
-
-
Save Sarapulov/d5410201f1c520c78f55863d08e28b99 to your computer and use it in GitHub Desktop.
Help Center cutomizations Preset Subject field based on custom field value, Hide Subject, Move Subject and Description fields.
This file contains hidden or 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
/************************************************************ | |
Help Center cutomization (ver 1.0.1) | |
Preset & hide Subject field based on custom field value, | |
Move Subject and Description fields. | |
************************************************************/ | |
if (document.location.search.indexOf('ticket_form_id') > -1) { | |
(function () { | |
var settings = { // change settings here | |
"hide_subject": true, | |
"133425":"request_custom_fields_31616405", | |
"142789":"request_custom_fields_31627285" | |
}, | |
form_id = window.location.href.split('ticket_form_id=')[1].match(/\d*/), | |
field_id = settings[form_id], | |
$att = $('div.form-field').last(), | |
$subject = $('.request_subject'), | |
$subject_input = $('#request_subject'), | |
$field = $('#'+field_id), | |
field_val = $field.siblings('.nesty-input').text(), | |
form_val = $('.request_ticket_form_id').children('.nesty-input').text(); | |
// set suject | |
if (field_id) { // only run on known ticket forms | |
if (settings.hide_subject) $subject.hide(); | |
$subject_input.val(form_val); // default subject to ticket form title | |
$field.on('change',function(e){ // sync field and subject | |
var new_field_val = $field.siblings('.nesty-input').text(), | |
other_val = (form_id == "142789") ? " - " + HelpCenter.user.name : ""; | |
$subject_input.val(new_field_val + other_val).change(); | |
}); | |
// move fields | |
$subject.insertBefore($att); | |
$('.request_description').insertBefore($att); | |
$('.suggestion-list').insertAfter($subject); | |
} | |
})(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment