I created a form using some user inputs, and linked it to a database I created. It works great, for the most part.
Unfortunately, when a user fills out the form and hits submit, if all fields are valid, it clears the fields (which is fine), and then highlights them as red.
The only code I used was my attempt at fixing this, which failed. It looked something like this:
function fields_are_valid () {
var fields = $w("#DaycareForm").children;
for (var i = 0; i < fields.length; i++) {
var field_name = fields[i].id;
var is_valid = $w(`#${field_name}`).valid;
// Skip the submit button - there's no such thing as a valid/invalid button
if (field_name === "btnSubmit")
{
continue;
}
if (!is_valid)
{
// Some field wasn't valid
return false;
}
}
// All fields are valid
return true;
}
function reset_all_fields () {
var fields = $w("#DaycareForm").children;
for (var i = 0; i < fields.length; i++) {
var field = fields[i];
console.log(`Resetting Field: ${field.id}`);
$w(`#${field.id}`).resetValidityIndication();
}
}
export function submitbutton_click(event) {
if (fields_are_valid())
{
reset_all_fields();
}
}
submitbutton_click is triggered onClick of the submit button.
fields_are_valid() seems to work. reset_all_fields() does not.