Working with input validation.

Hi, I need some help please.
I have a manual form which I populate with data from a collection. Two input boxes have validation set to required. I want a function that will tell me if all input boxes are valid and return true or false.
I have the following code

export function inputFirstName_change(event) {
if (inputFormValid())
    $w('#buttonRegister').enable();
else
    $w('#buttonRegister').disable();
}
export function inputLastName_change(event) {
if (inputFormValid())
    $w('#buttonRegister').enable();
else
    $w('#buttonRegister').disable();
}

function inputFormValid() {
let firstNameValid = $w('#inputFirstName').valid;
let lastNameValid = $w('#inputLastName').valid;
if (firstNameValid) {
    if (lastNameValid) {
        return true;
    }
}
return false;
}

But the change events don’t seem to indicate an immediate change to the value. For example if I changed the data from empty to something it says valid false. If I then change it back to empty it says true. If I change from something to something else it says true. Its like its checking for valid before the actual data is changed in the input box.
Should I build in some form of delay?

Figured it out. I have to have $w.onready(…….