The code works but not 100%...

Would anyone be willing to offer some advice on the below code? I’m trying to achieve when all relevant fields have a value then it will perform a function, I had some previous code prior it but was very long as I have 7 boxes each for 8 participants.

export function participantsContinue_click(event) {
       let participantNmb = $w('#participants').value;  
       for (let i = 1; i <= participantNmb; i++)  
       if ($w(`#name${i}`).value && $w(`#contactNumb${i}`).value)(console.log("Variable value " + i + "           " + "Dropdown value " + participantNmb)) 
}

So the code works but a flaw is that if at least the first name and contact number are valid then it will perform the function because it has a value, I need it to make sure it has all of the relevant values to match the dropdown value. I played with many varieties for the past 4 hours but no dice.

Thank you!

Have you seen this Wix tutorial for a guide.
https://www.wix.com/corvid/example/custom-validations

https://support.wix.com/en/article/corvid-about-validating-user-input-with-code
https://support.wix.com/en/article/working-with-user-input-validation-in-the-settings-panel
https://www.wix.com/corvid/reference/$w.ValidatableMixin.html
https://www.wix.com/corvid/reference/$w.TextInput.html

@sailorcihan thanks for the info. As I mentioned I have working code but its around 300 lines long because of the amount of user inputs to check, the style of the code is the same as in the example you have provided, hence the reason for trying to shorten and improve the code.