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

Question

Question

Check The Value of a Radio Button on the Next Form

asked on April 14, 2017 Show version history

I have multiple forms. Throughout the process, users have the ability to set or change the Specification field to either Yes or No. Once it hits the Engineering Manager (EM) role, when the EM's form loads, it must evaluate what was chosen for that radio button. If it's "yes", it must set another field (qae) to required.

 

$(document).ready(function(){
//set QAE to required if specification = yes
  if ($('.specification input').val() == 'Yes')
  {
    $('.qae label').append('<span class="cf-required">*</span>');
    $('.qae input').attr('required', 'True');
  } else {
    $('.qae span.cf-required').remove();
    $('.qae input').removeClass('required').removeAttr('required');
    };
});

It's not working. I'm sure I'm doing something wrong! It worked great when I initially had on "on change" but then I had to allow previous users to answer that question.

0 0

Answer

SELECTED ANSWER
replied on May 2, 2017
$(document).ready(function(){
//set QAE to required if specification = yes
  $('.specification input').change(function () {
  $(".specification input:checked").each(function(){
    if ($(this).val() == "Yes")
      {
        $('.qae label').append('<span class="cf-required">*</span>');
        $('.qae input').attr('required', 'True');
      }
    else
      {
        $('.qae .cf-label span.cf-required').remove();
        $('.qae input').removeClass('required').removeAttr('required');
      }
  });
  });
});  //close document.ready

I was concerned that the user, at that stage in the process, would want to change the decision, so I also allowed for a "change".

1 0

Replies

replied on April 14, 2017

Hi Gloria,

I think you need to check the ":checked" state of the relevant input. I was able to make it work with this (only change from your code is the condition in line 3):

$(document).ready(function(){
//set QAE to required if specification = yes
  if ($('.specification input[value=Yes]').is(':checked')) {
    $('.qae label').append('<span class="cf-required">*</span>');
    $('.qae input').attr('required', 'True');
  } else {
    $('.qae span.cf-required').remove();
    $('.qae input').removeClass('required').removeAttr('required');
  }
});

This was tested by setting the value of the radio buttons using URL parameters.

Hope this helps!

0 0
replied on June 13, 2017

Ultimately, I used:

//set QAE to required if specification = yes
  $('.specification input').change(function () {
    if ($(this).val() == "Yes")
      {
        $('.qae label').append('<span class="cf-required">*</span>');
        $('.qae input').attr('required', 'True');
      }
    else
      {
        $('.qae .cf-label span.cf-required').remove();
        $('.qae input').removeClass('required').removeAttr('required');
      }
  });
  $(".specification input:checked").each(function(){  
    $(this).trigger('change');
  });

 

0 0
replied on April 14, 2017

Gloria,

Another way to do it without the coding is to make the QAE field a required field in the Layout Section.  Then all you have to do is set the Field Rules for the form so that the field QAE is set to Show when the Radio Button 'Specification' is set to 'Yes'.  If it's set to 'No', the field doesn't show, and even though it was set as required it won't require it because it's hidden and the form will submit without it.

replied on April 14, 2017

Gloria,

Another way to do it without the coding is to make the QAE field a required field in the Layout Section of the Engineering Manager's form.  If it's not a separate form, you can make a copy to use for that task.  Then all you have to do is set the Field Rules for the form so that the field QAE is set to Show when the Radio Button 'Specification' is set to 'Yes'.  If it's set to 'No', the field doesn't show, and even though it was set as required it won't require it because it's hidden and the form will submit without it.

0 0
replied on May 2, 2017

Good idea but I do need it to show. I have it set that on blue, if the field is blank, insert N/A. But thanks for idea!

0 0
SELECTED ANSWER
replied on May 2, 2017
$(document).ready(function(){
//set QAE to required if specification = yes
  $('.specification input').change(function () {
  $(".specification input:checked").each(function(){
    if ($(this).val() == "Yes")
      {
        $('.qae label').append('<span class="cf-required">*</span>');
        $('.qae input').attr('required', 'True');
      }
    else
      {
        $('.qae .cf-label span.cf-required').remove();
        $('.qae input').removeClass('required').removeAttr('required');
      }
  });
  });
});  //close document.ready

I was concerned that the user, at that stage in the process, would want to change the decision, so I also allowed for a "change".

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

Sign in to reply to this post.