最近の検索


最近の検索はありません

Prefill and hide Subject & Description fields of specific form on New Request Template



image avatar

Ifra Saqlain

Zendesk LuminaryMost Engaged Community Member - 2022Most Engaged Community Member of The Year - 2021Community Moderator

投稿日時:2022年10月20日

Hello Everyone,

Credit

Zendesk Product(s): Zendesk Guide

Code Requirement: JavaScript

Template: New Request page

Scenario: Prefill the subject and description fields (if fields are required) and then hide both fields or only one field (depends on requirement).

 

Quetion: 

How to hide subject and description on new request template for the specific form?

 

Answer:

You want to hide the fields only for one form then check the form ID using the window location code with the IF condition using the JavaScript.

Source:
  
if (window.location.href.indexOf("00000000") > -1) {
      document.querySelector('.request_subject').style.display= "none";
      document.querySelector('.request_description').style.display= "none";
}



Note: Remove 00000000 and add your form-id.

 

 

Output:


Form One - With subject and description field.






Form Two - Subject and description fields are hidden because I added the form ID of this form in the script code.

 

 

Where to add the code?

You can see how I added the code to the script.js file inside the function.

Screenshot:

 

i). Go to Help Center > Guide Admin > Customize Design > Edit code.

ii). Find the script.js file.

iii). Add the shared code to hide subject and description field on new request template.

iv). Make sure code should be inside the DOMContentLoaded

 

Open Tag:

 

 

Close Tag:

 

 

Quetion:

How to get prefilled subject and description fields of a ticket of a specific form on new request template?

 

Answer:

If both fields are required then you can't submit a ticket without filling these. 

To get prefilled fields of specific form, use the given code.

Source:

 if (window.location.href.indexOf("00000000") > -1) {
      document.querySelector('#request_subject').value= "Write your text for subject field.";
      document.querySelector('#request_description').innerHTML= "Write your text for description field.";
  }




Note: Remove 00000000 and add your form-id.
 

 

 

Output:

 

 

Where to add the code?

 

i). Go to Help Center > Guide Admin > Customize Design > Edit code.

ii). Find the script.js file.

iii). Add the shared code to hide subject and description field on new request template.

iv). Make sure code should be inside the DOMContentLoaded

 

Open Tag:

 

 

 

Close Tag:

 

 

 

Important: If your fields are required (if you have set) and you hide both then request form will not be submit. Use the below code to prefill and then hide the fields.

Source:

  if (window.location.href.indexOf("00000000") > -1) {
// Autofill subject field    
  document.querySelector('#request_subject').value= "Write your text for subject field.";  

// Autofill description field    
   document.querySelector('#request_description').innerHTML= "Write your text for description field.";
      
// Hide subject field     
  document.querySelector('.request_subject').style.display= "none";
     
// Hide description field 
 document.querySelector('.request_description').style.display= "none";
  }

 

NOTE: If this line of code doesn't work for anyone:-

  document.querySelector('#request_description').innerHTML= "Write your text for description field.";

they can use this line instead of the above line of code.

  document.querySelector('.request_description > textarea').value = 'Write your text for description field.';

 

 

Thanks :)

 

 


4

69

69件のコメント


1263169183150 I added the code but still the subject and description field is not hidden.
Can you help fixing it
 

0


Hi Ifra Saqlain, this is something i've been searching a while for and just come to implement in our help centre but i think i'm experiencing the same issue as its now V4.1.0 so anything referenced here is not right. Is anyone able to help as I really need the ability to input some wording by default into the description on our requests

1


I just realized the new brand has Copenhagen v4.1.0, while the previous one is at Copenhagen v3.3.0. 

Do you know how we might be able to get similar code for the 4.1 version, or perhaps how to set up the new brand with an older version of Copenhagen?

0


I created the brand and help center that this form is connected to within the last couple of weeks and have noticed that its new_request_page.hbs and document_head.hbs are significantly different from my other brands. The others look similar to your screenshots, however this new brand's new request page code looks like this and unfortunately isn't responding correctly to the code you provided.

<div class="container-divider"></div>
<div class="container">
 <div class="sub-nav">
   {{breadcrumbs}}
   <div class="search-container">
     <svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" focusable="false" viewBox="0 0 12 12" class="search-icon" aria-hidden="true">
       <circle cx="4.5" cy="4.5" r="4" fill="none" stroke="currentColor"/>
       <path stroke="currentColor" stroke-linecap="round" d="M11 11L7.5 7.5"/>
     </svg>
     {{search submit=false}}
   </div>
 </div>

 <h1>
   {{t 'submit_a_request'}}
 </h1>

 <div id="main-content" class="form">
   <div id="new-request-form"></div>
 </div>
</div>

<script type="module">
 import { renderNewRequestForm } from "new-request-form";

 const container = document.getElementById("new-request-form");

 const settings = {{json settings}};

 const props = {
   requestForm: {{json new_request_form}},
   newRequestPath: {{json (page_path 'new_request')}},
   parentId: {{json parent.id}},
   parentIdPath: {{json parent.url}},
   locale: {{json help_center.locale}},
   baseLocale: {{json help_center.base_locale}},
   hasAtMentions: {{json help_center.at_mentions_enabled}},
   userRole: {{json user.role}},
   userId: {{json user.id}},
   brandId: {{json brand.id}},
   organizations: {{json user.organizations}},
   answerBotModal: {
     answerBot: {{json answer_bot}},
     hasRequestManagement: {{json help_center.request_management_enabled}},
     isSignedIn: {{json signed_in}},
     helpCenterPath: {{json (page_path 'help_center')}},
     requestsPath: {{json (page_path 'requests')}},
     requestPath: {{json (page_path 'request' id=answer_bot.request_id)}}
   },
 };

 renderNewRequestForm(settings, props, container);
</script>

I removed the "wysiwyg: true," line from the new request page as well during testing.

When I attempt to update the page to look similar to my other brands, I'm prompted with “request_form does not exist”.
 

0


Hi Jenny,I hope you got your solution as well if not please let me know :)

 

 

Thank You

 

0


Hey Hannah, I'm good I hope you also. 

 

You can use this code to autofill and then hide the both fields.

 

Step 1: Remove  'wysiwyg=true' from the form.

 

Current-

 

 

 

 

After-

 

 

 

 

Step 2: Add this given code at the bottom in the script file.

 

 

 

Code- 

 if (window.location.href.indexOf("360003074611") > -1) {
     document.querySelector('#request_subject').value= "Write your text for subject field.";
     document.querySelector('#request_description').innerHTML= "Write your text for description field.";
     document.querySelector('.request_subject').style.display= "none";
     document.querySelector('.request_description').style.display= "none";
 }

 

 

You need to remove my form ID and add your form ID where you wanna hide these fields.

 

First, open that form and then you will see the form ID in the search-bar.

 

 

 

Copy that and add in the script code here:

 

  if (window.location.href.indexOf("Add Here") > -1) {

 

 

 

If any query Feel free to ask :)

Thanks

 

0


Hi all, 

Hoping to get some help with hiding and auto-filling the subject and description fields for a single form. I had gotten it working on a previous form but mirroring the changes isn't giving me any results. Currently testing this code and it doesn't seem to be working properly:
 

I've also tried some of the other solutions that have been given in this article without any luck. 

0


1263169183150  - Long time since we've talked. I hope you've been well! Echoing everyone else's sentiment here about how awesome you are!!! :)

As always, I'm here to ask for your help. Are you able to assist with making the subject and description field hide on a specific drop-down value? We have a team that has several different functions and they want to have their subject line pre-populate and hidden on specific topic selections. Additionally, they want the description field to have a pre-populate text (not necessarily hidden). Is this possible? Here's the field id and the drop-down values:

<label id="request_custom_fields_29365922002331_label" for="request_custom_fields_29365922002331">What can we help you with?</label>

                           <input type="hidden" name="request[custom_fields][29365922002331]" id="request_custom_fields_29365922002331" autocomplete="off" data-tagger="{&quot;label&quot;:&quot;Associate Lease&quot;,&quot;options&quot;:[{&quot;label&quot;:&quot;Apply for an Associate Lease&quot;,&quot;value&quot;:&quot;associate_lease__apply_for_an_associate_lease&quot;},{&quot;label&quot;:&quot;Associate Lease Renewal&quot;,&quot;value&quot;:&quot;associate_lease__associate_lease_renewal&quot;},{&quot;label&quot;:&quot;Associate Move Outs&quot;,&quot;value&quot;:&quot;associate_lease__associate_move_outs&quot;}]}]" aria-required="true" aria-labelledby="request_custom_fields_29365922002331_label"/>

0


Hi,

 

I was wondering if anyone could assist with this functionality. I am trying to hide & prepopulate the Description and Subject Fields on one specific form, however the below code has no effect on my form: 

 

 if (window.location.href.indexOf("21346992414237") > -1) {
// Autofill subject field    
 document.querySelector('#request_subject').value= "Write your text for subject field.";  

// Autofill description field    
  document.querySelector('#request_description').innerHTML= "Write your text for description field.";
     
// Hide subject field     
 document.querySelector('.request_subject').style.display= "none";
    
// Hide description field 
document.querySelector('.request_description').style.display= "none";
 }

 

Thanks 

 

Mikey

0


1263169183150 Bummer! No problem! Thought this could make it easier for our agents but I can go with a more standard populating without the customization of adding the selection from the dropdown. Thank you for all your help!

0


サインインしてコメントを残してください。

お探しのものが見つかりませんか?

新規投稿