Hi folks. I am setting a text input’s validity.valid to false in an if/else block. I have confirmed that this is working properly, i.e. the text input validity is correctly set to false. However, when $w ( ‘#hotspotAddressInput’ ). updateValidityIndication () , it is not changing state to show a red border. The text input is correctly indicated as invalid when it is empty, as it is a required input.
The relevant code block:
export async function hotspotAddressInput_input(event) {
try {
let hotspotAddress = $w('#hotspotAddressInput').value;
const endpoint = "https://api.helium.io/v1/hotspots/" + hotspotAddress;
let jsonResponse = await getJSON(endpoint);
if (!('error' in jsonResponse) && hotspotAddress != '') {
$w('#hotspotAddressInput').validity.valid = true;
$w('#hotspotAddressInput').resetValidityIndication();
let hotspotStatus = jsonResponse.data.status.online;
let hotspotName = jsonResponse.data.name;
session.setItem("hotspotAddress", hotspotAddress);
session.setItem("hotspotStatus", hotspotStatus);
session.setItem("hotspotName", hotspotName);
$w('#hotspotNameText').text = hotspotName + ", " + hotspotStatus;
let fadeOptions = {
"duration": 500,
"delay": 0
};
$w('#hotspotNameText').show("fade", fadeOptions);
} else {
session.clear();
$w('#hotspotAddressInput').validity.valid = false; // setting validity.valid to false
console.log($w('#hotspotAddressInput').validity.valid)) // correctly logging "false"
$w('#hotspotAddressInput').updateValidityIndication(); // input still shown as valid despite this expression
if (hotspotAddress == '') throw "hotspotAddressInput value missing";
$w('#hotspotNameText').text = jsonResponse.error;
let fadeOptions = {
"duration": 500,
"delay": 0
};
$w('#hotspotNameText').show("fade", fadeOptions);
}
catch (error) {
console.warn(error)
return error;
}
I have tried putting $w(‘#hotspotAddressInput’).updateValidityIndication() in setTimeout() with a small delay with no luck. I have also tried onCustomValidation() but I find it rather unintuitive, and I’m not sure it’s appropriate as I want to invalidate the input based on a getJSON response, not the value of the input.
Any pointers are much appreciated. Thanks in advance!