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

Question

Question

Using Javascript to Make Bullet Items Required

asked one day ago

Based on a previous decision, I want to use JavaScript to make some fields required.

$(document).ready(function(){

//Set Fields to Required
  //If Request Type = New, Make Additional Fields Required
  if ($("input[id^=Field119-0]").is(':checked'))
  {
      $('.expectedHours input').prop('required', true).change();
      $('.expectedHours label').append('<span class="cf-required">*</span>').change();
      $('.overtime input').prop('required', true).change();
      $('.overtime label').append('<span class="cf-required">*</span>').change();
      $('.perDiem input').prop('required', true).change();
      $('.perDiem label').append('<span class="cf-required">*</span>').change();
      $('.travel input').prop('required', true).change();
      $('.travel label').append('<span class="cf-required">*</span>').change();
  }

});  //close document.ready

Works great except for radio buttons. It goes a little overboard with the red asterisks. I don't want yes no to have them:

0 0

Answer

SELECTED ANSWER
replied one day ago

For your Radio Buttons, instead of using "label" (which is on all radio choices as well), use ".cf-label" (only on the field label).

$('.overtime .cf-label').append('<span class="cf-required">*</span>').change();

 

1 0

Replies

replied one day ago

In addition to what Bert posted, instead of using 'input', use '.choice>input[type="radio"'.  Otherwise you will get double parsley messages indicating a value is required for each radio button choice.

$('.overtime .choice>input[type="radio"').prop('required', true).change();

1 0
replied 18 hours ago

THANK YOU! Both solved my problem.

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

Sign in to reply to this post.