Reject text input based on API response

I’d like add custom validation to a text input so that when an API response is invalid, the text input is rejected and the validation indication is updated to reflect this.

async function processInputs(inputA, inputB) {
 await getJSON("https://api.postcodes.io/postcodes/" + inputA)
    .then(json => {
 if(json.status === 200) {
            console.log("valid postcode");
            $w('#inputA').resetValidityIndication();
            return json.result.parliamentary_constituency;
        } else {
            console.log("invalid postcode");
            // reject $w('#inputA') here
            // update validation indication here
 }
 // function continues...

where $w(‘#inputA’) is the text input.

I’ve looked over the onCustomValidation stuff but it seems that’s only useful for rejecting inputs with a static validator, so I thought one option would be to reject it based on how an if/else statement resolves.

Any help is greatly appreciated!

1 Like

Bump!

I need to a similar thing.