Changing attachment label in request form.
Answered
Posted Mar 14, 2022
Is there a way to change the "attachment (optional)" label on the request form, to something else?
1
19
Posted Mar 14, 2022
Is there a way to change the "attachment (optional)" label on the request form, to something else?
1
19 comments
Jessica Strozyk
Hi Ifra Saqlain,
Thanks, that worked. Unfortunately, it broke the language selection that we have in the footer – it was not possible to select a different language anymore. Any idea why?
I used dynamic content instead of the text:
0
Ifra Saqlain
Hi Jessica Strozyk,
You can try this code:
0
Jessica Strozyk
Thanks for all this helpful information.
I have another question: Is it also possible to edit the "Add file or drop files here" text?
0
Brandon Tidd
Hey John Kenny -
I'm pretty sure you're going to need to use the tag associated with the value 'Yes'
If(selectedValue === 'my_yes_tag')
Try that and let us know if it resolves your issue
0
John Kenny
Thanks Brandon
I am trying to get this to work by adding your script to the script.js file.
I have jQuery already in my theme.
I have a dropdown menu - say field ID 54321
If the value is Yes I want to hide the attachment field, but this doesn't appear to work.
Here is my code below taken from what you kindly provided:
$(document).ready(function() { // Replace 'custom_field_12345' with your actual custom field's ID
var customFieldSelector = '#request_custom_field_54321';
// Function to show/hide the attachment field
function toggleAttachmentField() { var selectedValue = $(customFieldSelector).val();
// Replace 'value_to_hide' with the value that should hide the attachment field
if(selectedValue === 'Yes') { $('label[for="request-attachments"]').hide(); $('#request-attachments').hide(); } else { $('label[for="request-attachments"]').show(); $('#request-attachments').show(); } }
// Initial check in case the form is pre-filled or when the page loads
toggleAttachmentField();
// Set up the change event listener
$(customFieldSelector).change(toggleAttachmentField); });
0
Brandon Tidd
Hey John Kenny
Yes, both of these should be possible.
To change the format of the text you're appending to a Zendesk custom field using JavaScript, you can use jQuery to target the specific label and then apply HTML with the desired styling.
Let's say you want to append text to a label for a custom field and make that text bold. Here's how you could modify your current code snippet:
var label = $('label[for="request_custom_field_12345"]'); // Replace with your actual custom field ID label.html(label.html() + "<strong> ADD ANY TEXT HERE</strong>");
This code retrieves the current HTML of the label, appends the bold text, and then sets the new HTML back on the label.
If you only need to change the text content without appending anything, you can directly set the HTML like this:
var label = $('label[for="request_custom_field_12345"]'); // Replace with your actual custom field ID label.html("<strong>ADD ANY TEXT HERE</strong>");
And if you want to add a class to the label for CSS styling:
var label = $('label[for="request_custom_field_12345"]'); // Replace with your actual custom field ID label.addClass('your-custom-class'); label.html("ADD ANY TEXT HERE");
Then, in your CSS, you would define
.your-custom-class
with the desired styles.Remember to replace
"request_custom_field_12345"
with the actual ID of your custom field. You can typically find this ID by inspecting the HTML of your Zendesk form and looking for theid
attribute of the custom field's<input>
,<select>
, or<textarea>
element.Making the attachment required conditional is a little bit more complex since it is a default field.
0
John Kenny
This is excellent and just what I was looking for.
I do have a couple of questions though....
1. Could I format the appended text - change color etc?
2. Is there a way to have the Attachment element as being conditional. I.E - only display it if a user checks the box of a field in the form?
0
Ifra Saqlain
Hi Sandesh Kamath, if possible then explain some more about the query.
0
Basrur Sandesh Kamath
Do we know if we can limit any specific attachment type on this attachment add or drag drop ???
0
Max
Ifra Saqlain
That Guide is unfortunately not public .. only for authenticated users.
Any other option ? 🫤
0
Sign in to leave a comment.