@flo got back to me on this one and says you can do it if you trigger the workflow on click on the button element (instead of on submit on the form container element).
You would then need to manage the verification of input fields manually with actions so it would be a lot of work
I’ve added your question to our user research so we keep it in mind when exploring new functionalities like multi-branching and adding a throw error action.
I ended up just using inline error messages that show an error message below the input field after a user clicks on the submit button, if the field is invalid.
Here is my solution incase anyone else is looks at this later on:
You cannot put the workflow in onSubmit as the actions will not run in the workflow if there are invalid inputs
I put the javascript in the onClick workflow for a SUBMIT button.
add an HTML Attribute to all of the fields that you want to be validated with key = validate_input
Add an empty text element below the input element with an HTML attribute with key = error_for, and value = ##The name of the field this is an error message for##
This is the javascript in the workflow, onSubmit action:
var valid = true, error = "", field = "", form = "", invalid_inputs = [];
form = document.getElementById("page2-form");
form.querySelectorAll('[validate_input]').forEach(element => {
field = element;
error = document.querySelectorAll('[error_for=' + field.name + ']');
if (!field.checkValidity()) {
valid = false;
field.classList.add("input_error");
error[0].innerHTML = field.validationMessage;
// invalid_inputs.push(field); use this is if you want collect the list of input fields that have errors to show a summary meesage.
} else {
field.classList.remove("input_error");
error[0].innerHTML = "";
}
});
return valid; // you can use this in the next action for your form submit step
@Joyce I was wondering if there is a no code way to do more complex validation, coming from the appsheet world they have a valid if formula option this will for sure improve the process for those of us who don’t know how to code.
The thread was created in May 2022. I think you could do this in no-code in WeWeb now.
For example, you could create one formula per condition and then re-use all those formulas in your own validIf formula, and display an error even before the user submits the form, like Carri did here.
To illustrate the idea of re-usable formulas, you can see in the screenshot below that we use a formula that calculates the number of minutes spent on calls (minutesSpent) inside another formula to calculate how much of our mobile plan we spent (percentSpent):
@Dorian If this is still relevant. take the textField that has a rule like “minimum 8 long” then on the text color property, take the length of the password and see if its over 7. if yes return the green color.
let me know if you want some more details or examples.