How can I make fields required only if expanded?

I am very new to this and I’ve spend many hours putting together the form I want and it’s working good except one thing. I have a booking form and the radio button asks if there are 1 or 2 guests. I have two boxes that are collapsed and based on the radio button selection it then expands either 1 or 2 boxes that have the fields needed for each guest and most of the input fields within the boxes are marked as ‘required’. The problem is that if they select 1 person the box for the 2nd person stays collapsed but then the form can’t be submitted because the collapsed fields are required but not completed. Is there a way to make the fields in the 2nd box only required if it’s expanded or if radio button 2 is selected?

I’ve been searching for a solution for hours. Can someone please help me? It would be greatly appreciated!!

Hi John, if the elements are collapsed, you won’t be able to run any code on them until they’re expanded, that means, collapsed elements won’t be validated, so it doesn’t matter.

In a nutshell, you don’t need to worry about the validity of a collapsed element, collapse it and it will not be checked.

Hi John,

Collapsed elements are checked for validation.

This is a simple one line statement you could use for the elements involved:

$w("#input").required = ($w("#input").collapsed) ? false:true;

I had a form that has some elements, some of them are required, but the form submission process didn’t care about them while they were collapsed.

needed this answer - thanks!

It May Help You :

  1. Turn on Dev Mode.

  2. Disable the "Submit / Next " Button By Default.

  3. Write OnChange for radio Button

  4. Based on user value from RadioButton, You can Hide/Collapse the Details Fields.

  5. Write the Logic for Until the user enters the first field , the Submit Button Remains Disable.
    You need to user the Value from Radio Button

  6. If User Value is 2 , Diable the Submit Button.
    Actually You can Write 2 IF Functions for Each Case
    Thanks