Validation Check based on Switch State

I build myself a contact form using a multistate box and one of the states includes a switch that shows/hides a text input field.

If the button is “off” it is hidden and if it is “on” it shows. Now I have a check in the state which then enables/disables the button that goes to the next state (window) in the multistate box based on if the required fields are filled or not.

What I can’t figure out is how to include a check of the “Company Name” text input field based on if it is shown or not.

So that if it is hidden it should not be included in the check, but if shown should be considered.

Code-Snippet:
//ValidationState1
$w ( “#firstName, #lastName, #companyName” ). onInput ( function () {
if ( $w ( “#firstName” ). value.length > 0 && $w ( “#lastName” ). value.length > 0 && $w ( “#companyName” ). value.length > 0 ) {
$w ( “#nextButton1” ). enable ();
} else { $w ( “#nextButton1” ). disable (); }
});

Thank you in advance.

Hidden-Check…

if ($w("#companyName").hidden === true) {....do something}
else {...do something else...}

Collapsed-Check…

if ($w("#companyName").collapsed === true) {....do something}
else {...do something else...}