How to pre-fill description box based on Custom Field value
AnsweredHi All,
I'm seeking assistance on how to autopopulate the description box based on the value of a particular custom field. This for when an end user submits a form.
The custom field is a drop-down menu containing only 2 options
The Description box has been hidden to let us customise the ticket description.
This is my current code so far:
$('.form-field.request_description').hide();
if ($("#request_custom_fields_360025027158")=="OPTION A") {
$('#request_description').val('Description 1');}
else
{$('#request_description').val('Description 2');}
Any and all assistance would be appreciated.
-
Hi Lou,
Try the below code:
tinymce.get("request_description").setContent("<p>Description 1</p>");
Let me know how it goes for you.
Thanks
-
When you say description, are you referring to the subject field? If so, we use a trigger and extension to make that change. It's completely automated based on if the field has a value.
-
Hi Patrick Lieu, I got something for you:
HTML: Add at any page
<div id="option1" class="group">Description One</div>
<div id="option2" class="group">Description Two</div>
<div id="option3" class="group">Description Three</div>
<div id="option4" class="group">Description Four</div>
<select id="selectMe">
<option value="option1">option1</option>
<option value="option2">option2</option>
<option value="option3">option3</option>
<option value="option4">option4</option>
</select>Script code:
$(document).ready(function () {
$('.group').hide();
$('#option1').show();
$('#selectMe').change(function () {
$('.group').hide();
$('#'+$(this).val()).show();
})
});Output is:
I'm not sure but may be you can do something with this code via changing the classes in script code.
You can add script code only and add the classes of your custom dropdown.
Thanks
-
Ifra Saqlain the Output image is missing, can you please add. Trying to work out if this will work for our needs. Thank you :)
-
Hello, I am trying to add a description template based on a custom field id's and their associated tags. I listed custom field 1 and 3. Custom field 3 is a child field of Custom Field 1. My code worked fine up until last week. For some reason it stopped working and also disabled the users dropdown menu to view their activities and requests.
Here is the code I have added into the JS
/*
$(document).ready(function () {
var ticketForm = location.search.split("ticket_form_id=")[1];
if(ticketForm == 400000000000) {
$("#request_description").val();
}
});
function descriptionFormat(){
let serviceType = {
ID Tag1 : "1. Do you have the current version of the App? (Update version),
ID Tag 2 :""
}
let IssueType = {
ID Tag3 : "Does the member have the current App version?
}
const serviceTypeNode= document.getElementById(document.querySelector("#new_request > div.form-field.string.required.request_custom_fields_ID_1 > a").getAttribute("aria-controls"));
const config = { attributes: true, childList: true, subtree: true };
const serviceTypeCallback = function (mutationsList, observer) {
for (const mutation of mutationsList) {
if (mutation.attributeName == "aria-selected")
{
if (Object.keys(serviceType).indexOf(mutation.target.id)>=0) {
document.getElementById('request_description_ifr').contentWindow.document.querySelector("p").innerText = serviceType[mutation.target.id];
if (mutation.target.id == "ID_3"){
const IssueTypeNode= document.getElementById(document.querySelector("#new_request > div.form-field.string.request_custom_fields_ID#.required > a").getAttribute("aria-controls"));
issueTypeObserver.observe(IssueTypeNode, config);
}
}
else {
document.getElementById('request_description_ifr').contentWindow.document.querySelector("p").innerText = "";
}
}
}
};
const IssueTypeCallback = function (mutationsList, observer) {
for (const mutation of mutationsList) {
if (mutation.attributeName == "aria-selected")
{
if(Object.keys(IssueType).indexOf(mutation.target.id)>=0){
document.getElementById('request_description_ifr').contentWindow.document.querySelector("p").innerText = IssueType[mutation.target.id];
}
else{
document.getElementById('request_description_ifr').contentWindow.document.querySelector("p").innerText = serviceType["Issue Type Tag"];
}
}
}
};
const serviceTypeObserver = new MutationObserver(serviceTypeCallback);
const issueTypeObserver = new MutationObserver(IssueTypeCallback);
serviceTypeObserver.observe(serviceTypeNode, config);
}if (document.querySelector('#new_request a[aria-label="Please choose your issue below"]').innerText == "Form Name 1"){
descriptionFormat();
}
Please sign in to leave a comment.
5 Comments