How do I show a alert after validating an input field when the API is called?

While working with input widgets, how do I validate it when APIs are called?

Before calling the API, you can check isValid property of input. For e.g: On click of a button, you can write logic like this:

{{ (function() {
    if (!Input1.isValid) {
        // show alert 
    } else {
        // Input is valid, you can here call your API with