Hiding Standard Fields in Forms

Jordy Veldhuis
Jordy Veldhuis
  • Updated

Sometimes you want to hide certain standard fields in a form, such as subject and description, from users. For example, because these are filled in automatically or because you work with fixed ticket structures. With JavaScript, you can easily hide these fields and optionally pre-fill them.

 

✅ Recommended method - Via new-request-page.hbs:

Place the script directly in your new-request-page.hbs template, just like you do for attachment scripts. This is the most reliable approach because the DOM is guaranteed to be loaded and the form ID is read directly from the URL.

<script>
  $(document).ready(function() {
    var urlParams = new URLSearchParams(window.location.search);
    var formId = urlParams.get('ticket_form_id');
    
    if (formId === 'FORM_ID_HERE') {
      $('#request_subject').closest('div.form-field').hide();
      $('#request_subject').val('New ticket – Automatic subject');
    }
  });
</script>

👉  Replace FORM_ID_HIER with the correct form ID. The URL will then look like this when the form is opened: /hc/nl/requests/new?ticket_form_id=FORM_ID_HERE
 

Alternative - Via script.js (less reliable):

If it doesn’t work via the hbs template, you can try the methods below via script.js. Note: this does not always work well because the timing of DOM loading plays a role here.

var formId = $("#request_issue_type_select").val();

if (formId === 'FORM_ID_HERE') {
  $('.form-field.request_subject').hide();       // Hide subject
  $('.form-field.request_description').hide();   // Hide description

  $('#request_subject').val('New ticket – Automatic subject'); 
  $('#request_description').val('See filled fields below'); 
}

One last tip, if it doesn’t work immediately? Then check if the following is present in your script.js

<script 
  src="https://code.jquery.com/jquery-3.6.0.min.js" 
  integrity="sha256-/xUj+3OJUsyExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" 
  crossorigin="anonymous">
</script>

When is this useful?

  • When you want to enforce fixed ticket structures
  • If users are only allowed to fill in specific fields
  • For onboarding or request forms
  • When you want to standardize subject lines automatically