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

18 Comentarios

  • Raphaël Péguet - Officers.fr

    Hi Ifra Saqlain you seems very skilled(congrats!)

    Do you know the way to align side to side some fields? please

    Like this:

    Best regards! 🙏

    0
  • Ifra Saqlain
    Community Moderator
    Most Engaged Community Member - 2022
    Most Engaged Community Member of The Year - 2021

    @Raphaël Péguet, you can get it by CSS, pick the ID of your fields which you wanna set side by side and add the given CSS.

    .request_description,
    .request_subject {
    margin-right: 10px;
        float: left;
      width: 35%;
    }

    Only for example but you need to add your custom field's classes and set the width per your requirements.

     

    I took the class of subject field and description field and then add css code to style.css file.

     

    Output:

     

    If any confusion feel free to ask :)

    Thanks

    Team

    0
  • Raphaël Péguet - Officers.fr

    Dear Ifra Saqlain

    Sorry for the lateness of my answer I was in holidays just after asking,

    Thank you a lot for this incredible tip, so useful ! 

    Best regards,

    Raphaël

    0
  • Teresa

    Hi Ifra Saqlain, not sure if you can help. I've been over a few pages on hiding the subject from a form and auto-populating it using the script.js file using the following: 

     

    if ($("#request_issue_type_select").val() == "123456") {
        $('.form-field.string.required.request_subject').hide(); // Hide subject 
      $('#request_subject').val('Custom text here'); // Autofill subject

    What I'm looking to do is add a custom text field from the form to the beginning of the subject, in addition to some standard custom text. However, I'm not sure how to accomplish this with js. I did find where you can do it using a webhook, but I'd like to stay away from that and stick to code in the js file if possible. 

    Basically, I need to autofill the subject with (custom_text_field_12345) + ("Custom text here"). Do you know if this can be achieved? Thanks in advance for any input you can offer!

     

    0
  • Ifra Saqlain
    Community Moderator
    Most Engaged Community Member - 2022
    Most Engaged Community Member of The Year - 2021

    HI Nicole,

    If you already have a custom-text-field-1234 then simply do the following:

    // Autofill custom text field   
    document.querySelector('#custom-field-id-17365969036').value= "Write your text here";

    Where custom-field-id-17365969036, is the id of this element, you can get it by inspect tool

    Mouse hover over the field > right-click > select Inspect > see the id of field > copy that >  remove custom-field-id-1736596903 and paste that here.

     

    And,

    Write your text here : Remove this text in the code and write yours.

     

    To autofill the subject field then add the below code:

    // Autofill subject field    
      document.querySelector('#request_subject').value= "Write your text for subject field.";

     

    Here, subject id is same for all so you only need to update the text in the code.

     

     

    If you don't have custom text-field then create that first.

    Go to Admin Center click  Objects and rules in the sidebar, then select Tickets > Fields.

    After creating, you can see that custom field in your form then do the points which I share above.

     

    If any confusion feel free to ask :)

    Thanks

    0
  • Teresa

    Hi Ifra Saqlain! Thank you for helping! I may have not explained myself well. I don't need to autofill a custom field, the end user will still enter their value. I need to add a custom field to an autofill subject. Something like this: 

    $('#request_subject').val(('#custom-field-id-17365969036') 'Custom text here'); // Autofill subject

     

    The end result I'm looking for in the subject is something like: 

    "John Doe New Ticket Request"

    Where John Doe is what the end user entered for their name in the custom field, and New Ticket Request is what was autofilled for each ticket subject. I hope that better explains it!

     

     

     

     

    0
  • Ifra Saqlain
    Community Moderator
    Most Engaged Community Member - 2022
    Most Engaged Community Member of The Year - 2021

    Hi Nicole,  now I understood your query and it's possible, it could be done like this:

    var _x = $("#custom-field-id-17365969036").html();
    $('#request_subject').val(_x + ' ' + 'New Ticket Request');

    After creating ticket using this technique and making t live, check the ticket title in Ticket dashboard of Support.

    Try this and let me know. 

    0
  • Teresa

    Hi Ifra Saqlain , I just got done testing this. Instead of showing:  John Doe New Ticket Request

    Within Support it shows as:  undefined New Ticket Request

    I'm wondering if this is because there isn't a value for the field until submission? 

    0
  • Ifra Saqlain
    Community Moderator
    Most Engaged Community Member - 2022
    Most Engaged Community Member of The Year - 2021

    Nicole, can you share public URL of your HC? I wanna see.

    0
  • Teresa

    Hi Ifra Saqlain! I sure can! I'll leave the link up for a day or two. The direct form I'm trying to make this work for is: [link to HC]. The custom field I'm trying to get into the subject is the Name field. Ty!

    0
  • Ifra Saqlain
    Community Moderator
    Most Engaged Community Member - 2022
    Most Engaged Community Member of The Year - 2021

    Hey Nicole, copy and paste the given code and see the output:

    $("#request_subject").val("New request");
    $("#request_custom_fields_12929052282519").keyup(function(event) {
      var stt = $(this).val();
      $("#request_subject").val(stt + " New Request");
    });





    Output:

     

    let me know if it works for you.

    1
  • Teresa

    Ifra Saqlain Just tried the code. When I use this, it unhides the Subject field. I did try to add the line of code to hide it, but even with that in it didn't hide. 

    I added : $('.form-field.string.required.request_subject').hide();

    I tried it at a couple spots (above the new code, below the new code) and nothing worked. 

    0
  • Ifra Saqlain
    Community Moderator
    Most Engaged Community Member - 2022
    Most Engaged Community Member of The Year - 2021

    Nicole I just tried again:

    URL

     

    It is working, subject field already hidden in the form, I pasted that code and that is working.

     

     

     

    0
  • Teresa

    Hi Ifra, 

    I just messed with the code a little bit and got it to work! Thank you for being such a rockstar! I'm going to list what worked for me below in case anyone else stumbles on this. If you can unlink our HC that would be great. I wish I could upvote your posts more than once, lol!!

     

    //hide subject and autofill subject on submission for form
    if ($("#request_issue_type_select").val() == "FormID") {
      $("#request_subject").val("New request");
      $("#request_custom_fields_fieldID").keyup(function(event) {
      var stt = $(this).val();
      $("#request_subject").val(stt + " New Request");
    });
        $('.form-field.string.required.request_subject').hide(); // Hide subject 
    };

     

     

     

    0
  • Teresa

    Hi Ifra Saqlain Can you possibly unlink our HC two comments up? Thank you so much, and as always, I appreciate your help so very much!!

    0
  • Ifra Saqlain
    Community Moderator
    Most Engaged Community Member - 2022
    Most Engaged Community Member of The Year - 2021

    Thanks Nicole!

     

    0
  • Teresa

    Hi Ifra Saqlain, its the link in your comment on this page. TY!

     

    0
  • Ifra Saqlain
    Community Moderator
    Most Engaged Community Member - 2022
    Most Engaged Community Member of The Year - 2021

    Done!

    0

Iniciar sesión para dejar un comentario.

Tecnología de Zendesk