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

Question

Question

other_value Not Required

asked on September 13, 2022

Hello,

I have a radio button question with "Other".  The question is required. 

If they choose Other, the Other_Value is required.    I'd like the other_value not required (optional), when the user chooses 'Other'.

 

Here's what I'm using, but it doesn't seem to be working....

$('#Field160_other_value').addClass('greenBackground');  // used pinpoint the input box
$('#Field160_other_value').removeAttr('required');		
$('#Field160_other_value').removeClass('required'); 
$('#Field160_other_value').removeClass('parsley-error');
$('#Field160_other_value span.cf-required').remove();
$('#Field160_other_value').removeClass('parsley-error');

All help is appreciated!!

 

 

 

 

0 0

Replies

replied on September 13, 2022

Where is the code preceding this that actually triggers it?  You would want to wrap these statements within a change on the radio buttons like in the below example, keeping in mind to change .radioButtons to whatever the class of the radio buttons are.

$('.radioButtons input').on('change',function() {

      alert('a selection has changed');

      //existing code you have inside this change to evaluate the conditions

});

Now anytime the radio buttons are changed, you can evaluate whether or not you need to add or remove the required class/attributes.  You can leave the alert in there to help with making sure your code is making it inside the code block.  If you don't see an alert each time you change the radio buttons, then something is wrong with it.  You can comment it out or remove when you put this into production.  

Give me an update on how it turns out and if you still need further help once you get that part set up;  I imagine you would then need to add if/else statements to determine when to add or remove the required

0 0
replied on September 15, 2022 Show version history

I added my code into the change code I already had.  But it still doesn't work.  Somehow it's just not targeting that textbox.  I'm having the same results.  See below

  
  
      var OtherChecked = false;
    $('.relationship_to_student .choice').on('change', function () 
    {
          OtherChecked = $('#Field160_other').prop('checked');
         if (OtherChecked)
        {
              $('.Relationship_Other_Checked input').val('Other');
            $('.Relationship_Other_Value input').val($('#q160 input[type=text][name=OtherField160]').val());

 alert('a selection has changed');
          
$('#Field160_other_value').addClass('greenBackground');
$('#Field160_other_value').removeAttr('required');
$('#Field160_other_value').removeClass('required'); 
$('#Field160_other_value').removeClass('parsley-error');
$('#Field160_other_value span.cf-required').remove();
$('#Field160_other_value').removeClass('parsley-error');      
        
        }
        else
        {
              $('.Relationship_Other_Checked input').val('');          
              $('.Relationship_Other_Value input').val('');
        }
    });
    $('#q160').trigger('change');  //trigger it to check again.  First time is undefined.
  
  
 

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

Sign in to reply to this post.