You are viewing limited content. For full access, please sign in.

Question

Question

Make upload required in javascript

asked on October 7, 2021

How do I make an upload field required in JavaScript in Forms and have red asterix next to it?

0 0

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 8, 2021

I would use two uploads.  One is optional for when the "certain field" is not selected and one required when the field is selected.  Then use field rules to hide/show the fields based on the selected field value.

0 0
replied on October 8, 2021

thanks

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
replied on October 13, 2021

Thanks

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.