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

Question

Question

Set required field in collection based off radio value

asked on November 17, 2019

Hi All,

I've got a radio button with 2 values:

 

1. Standard

2. Breakdown/Emergency

 

I've also got a field collection underneath with a dynamic required field based on the above selection (Type).

What I'm trying to achieve is set the field (Type) to required in all collection sets (and also figure out how to display the red asterix on the label).

 

Here's what I have so far

$(document).ready(function(){
  $('#q79 input').change(function(){
    if ($(this).val() === "Breakdown/Emergency") {
       $('#q89 select').attr('required', 'True');
       $('#q89 select').append('<span class="cf-required">*</span>');
   }
  else{
     $('#q89 span.cf-required').remove();
      $('#q89 select').removeClass('required').removeAttr('required');
   }
  });
});

 

So far, it seems to set the first instance of Type (#q89) to required (without the label) but any additional collections are treated as not required.

 

Any help would be appreciated.

 

Thanks all.

 

0 0

Replies

replied on November 18, 2019

#q89 references a single field by ID

.className references all fields sharing a class name

In the advanced configuration of the field, you can add a class name, then reference all instances of the field in one shot with $('.className select')

This plan might backfire if someone is able to add a new collection set after choosing the radio button though. Is hiding the field using field rules not an option? A hidden required field will not be required.

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

Sign in to reply to this post.