Help center JavaScript cookbook

Return to top

12 Comments

  • Shawn Amsberry

    Is it possible to autofill a field that is a dropdown menu field?  Or does that only work for text entry fields?  I can successfully hide fields on various forms and autofill text fields like the subject and description, but I have not been successful with drop menus.

    Thanks!

    0
  • Cheeny Aban
    Zendesk Customer Care
    Hi Shawn,

    Are you trying to autofill a dropdown field on a ticket form? If yes, the Creating pre-filled ticket forms will help you
    0
  • Adam

    Hello,

    I'm looking for help on ticket forms in the Help Center. We currently have a URL in the description of a custom field. This allows our customer to reference the information on this page while filling out the form.

    The issue we have discovered is that when the customer clicks on the link it opens the URL in the same window as the Help Center. 

    Does anyone one know how to capture this via Javascript and force the link to open into a new tab within the users browser?

    0
  • DJ Buenavista Jr.
    Zendesk Customer Care
    Hi Adam,
     
    In regards to your concern, the following script involves custom coding. I would advise searching online for solutions, but I have found some from looking online. 
     
    You can check an example from StackOverflow, here. Another one for reference can be found here. 
     
    Thank you and have a wonderful day ahead!
     
     
    Kind regards,
    0
  • Adam

    Hey DJ Buenavista Jr.

    Thank you for your recommendation.

    I was able to find another solution with one of our Javascript engineers and is working as expected. I'll certainly keep the options you've shared in my back pocket if I have any issues with the one I'm using.

    const links = document.querySelectorAll("a");
      for (const link of links) {
        link.addEventListener('click', function (e) {
        if (e.target.href == 'http://google.com') {
            e.preventDefault();
            window.open(link.href, '_newtab' + Date.now());
          }
        });
    }
    0
  • DJ Buenavista Jr.
    Zendesk Customer Care
    Hi Adam,
     
    I'm glad to hear that you were able to find a suitable solution. Please don't hesitate to reach out anytime if you need further help or questions. 

    Have a wonderful day ahead!
     
     
     
    Kind regards, 
    0
  • T5 Admin

    Hey, 

    I'm trying to make it so that a custom date field can't select a date in the past. Is that possible?

    0
  • Tipene Hughes
    Zendesk Developer Advocacy

    Hey T5 Admin,

    Would you mind sending through a snippet of how your custom date field is currently functioning and I can put together a working example based on your code.

    Thanks!

    Tipene

    0
  • T5 Admin

    Hey Tipene Hughes

    The date field is just the custom date field that the user can edit. 

    0
  • Tipene Hughes
    Zendesk Developer Advocacy

    Hi T5 Admin,

    Thanks for clarifying that for me!

    Unfortunately, it's not possible to modify the behavior of the in-built custom field date picker. I can definitely see the use case for such a feature though, so I'd encourage you to create a post on the feature request community page. This will allow greater visibility to our product teams, as well as give others the opportunity to upvote and provide additional use cases for such a feature. You can find our guidelines around creating feature requests, here.

    Have a great day!

    Tipene

    0
  • Shawn Amsberry

    I'm successfully able to autofill only one custom field in a ticket form using the script.js file.  My method is:
    if(ticketForm == 7386956538260) {
    $('.form-field.request_subject').hide(); // Hide subject
    //Auto-fill fields//
    $('#request_subject').val('Agency/Application SPOC change request');
    $('#request_custom_fields_21608582').val('zendesk_assistance');
    $('#request_custom_fields_21626618').val('User_Management_incl_Permissions_ID_Req_/_Passwd_Reset_etc');
    $('#request_custom_fileds_21617267').val('Zendesk_Support_Portal');
    }

    My subject, a standard field, and field 21608582, a custom field, are auto-filling successfully.  The other two fields are not auto filling.  

    Any insight?

    Shawn A.

    0
  • Greg Katechis
    Zendesk Developer Advocacy

    Hi Shawn! My first thought would be that the last two options are drop-down or multi-select fields, which require that you pass in the tag for the value, as opposed to the field name. The syntax is slightly different with this being JSON as opposed to JQuery, but the general info can be pulled together from this article

    If that doesn't resolve the issue for you, could you let us know if you're seeing any console errors that could shed some light on this?

    0

Please sign in to leave a comment.

Powered by Zendesk