So my requirement is to work within Wix validation system. I don’t want to rebuild a validation system next to the one of wix (with all feature, like .valid .validity and validationMessage)
for instance, you will not be able to validate your form that way
let isformValid = inputSelectors.every(selector => selector.valid)
We can always find a workaround but for something as basic as input validation, I wish we wouldn’t have to come up a workaround
Managed to build this experience using both onChange and onCustomValidation
and here is the code
$w.onReady(() => {
$w('#input1').onChange(changeInput1)
$w('#input2').onCustomValidation(validateInputs);
});
function changeInput1() {
// force input2 to update the validity state
$w('#input2').value = $w('#input2').value;
}
function validateInputs(value, reject) {
let val1 = $w('#input1').value;
let val2 = $w('#input2').value;
if (val1 !== val2) {
reject('Both inputs should have the same value');
}
}
export function button2_click(event) {
console.log('input1:', $w('#input1').validationMessage, 'input2:', $w('#input2').validationMessage)
}