How do I make an upload field required in JavaScript in Forms and have red asterix next to it?
Question
Question
Replies
replied on October 8, 2021
Why do you want to use JavaScript to archive that? Can you just use the out-of-box "Required" option?
0
0
replied on October 8, 2021
No. The upload field will have to be required only based on if certain field is selected on the form.
0
0
replied on October 12, 2021
Hi Priya,
This is a common request we get too for the signature field.
For example, when the radio button option "No" is selected, then make the file upload required:
$(document).ready(function() { $('.fieldB label').append('<span class="cf-required">*</span>'); $('.fieldB input').attr('required','True'); $(".fieldA input").change(function(){ if ($('.fieldA input[value="Yes"]:checked').length > 0) { $('.fieldB span.cf-required').remove(); $('.fieldB input').removeClass('required').removeAttr('required'); } else { $('.fieldB span.cf-required').remove(); $('.fieldB input').removeClass('required').removeAttr('required'); $('.fieldB label').append('<span class="cf-required">*</span>'); $('.fieldB input').attr('required','True'); } }); });
.fieldA is the radio button CSS class
.fieldB is the file upload CSS class
0
0
You are not allowed to follow up in this post.