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

Question

Question

Make Signature Not Required if Checkbox is Selected?

asked on May 9, 2014 Show version history

We are working on a workaround for authenticated users saving forms so they show up in their Tasks in Forms. I have made a single checkbox field that when checked and the form is submitted will route the document back to the initiator of the form. That works great.

 

This form uses the Custom Signature fields that were supplied at Empower 2014. We need a way for the form to look to see if the checkbox is selected. If so, don't make the signature field required. If it isn't checked, the signature field should still be required.

 

This is the code that disables the submit button unless the signature is applied:

//disable submit button until signature is confirmed
    $('.Submit').attr('disabled', 'disabled');
    $('#donebutton').click(function () {
        $('.Submit').removeAttr('disabled');
        $('.sigwarning').hide();
    })
    //end disable submit button code

 

0 0

Answer

APPROVED ANSWER SELECTED ANSWER
replied on May 9, 2014 Show version history

If there's only one option for your checkbox, you could use the follow code (within your $(document).ready function), giving the checkbox field the checkbox CSS class.

$('.checkbox input').change(function () {
  $(this).is(':checked') ? $('.Submit').removeAttr('disabled') : $('.Submit').attr('disabled', 'disabled');
});

You could also check for a specific value:

 

$('.checkbox').change(function () {
    $(this).find('input:checked').val() == "some value" ? $('.Submit').removeAttr('disabled') : $('.Submit').attr('disabled', 'disabled');
});

 

 

 

0 0
replied on May 9, 2014 Show version history

Thank you for the reply Eric. I had at first forgot to add the CSS class. After adding it, it worked like a charm! Thank you!

0 0
replied on May 9, 2014

Eric, would you be able to do something similar to see if the checkbox is selected to not make required fields required?

0 0
replied on May 12, 2014

Yep. You'd do something like this, assuming the ro class has been added to your read-only fields.

 

$('.checkbox input').change(function () {
    $(this).is(':checked') ? $('.ro input').removeAttr('readonly') : $('.ro input').attr('readonly', true);
});

 

0 0
replied on May 12, 2014

Eric, I'm a little confused on this one. Shouldn't it be targeting required fields and not read-only fields? Just want to make sure I'm not missing something here.

0 0
replied on May 12, 2014 Show version history

Sorry, I misread your reply. Here's how you'd toggle required fields (assuming the req class has been added to the fields you want to toggle):

 

$('.checkbox input').change(function () {
  if ($(this).is(':checked')) {
    $('span.cf-required').remove();
	$('.req input').removeClass('required').removeAttr('required');
    
  } else {
    $('.req label').append('<span class="cf-required">*</span>');
    $('.req input').attr('required', 'True');
  }
});
   

 

 

1 0
replied on May 12, 2014

Not a problem. Thank you for the reply. I would use this in conjunction with the code to make the signature not required correct?

0 0
replied on May 12, 2014

Yes, just place it within your document.ready function.
 

0 0

Replies

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

Sign in to reply to this post.