Thought I would post a little tip on some field validation trick without the need to submit a change or creation to the database.
This is also for my reference along the way - always happy for anyone to let me know if this is good, bad practice and if there are other ways to do this:
Why?
I have a multi part form where I do not want the user to submit to the database until the end, however, I do want them to validate mandatory fields along the way to save scrolling back to the various sections.
I have two parts (this is just for illustration here, I have 5 parts, and 50+ fields of varying types on the main form I am working on).
On the page I have a custom state called ‘section’ and on page load its set to ‘1’
Group one
- Group one is visible if ‘section = 1’
Two fields that are mandatory with ‘this input should not be empty’ selected (important).
Each field has a hidden text element after it that is conditionally shown if the parent field is ‘isn’t valid’
A next button that runs a workflow and sets the state of the custom state ‘section’ to ‘2’ - once valid.
Two Bubble ‘Alerts’ on the page after each field (however this doesn’t matter where as they are not to be shown) and is where the magic happens:
On the next button you set a workflow to trigger and ‘alert’ that you setup on the page previously and specify to run this on each mandatory field but make sure you use ‘value is empty’.
When you click the next button the inputs are validated before the workflow set the state of ‘section’ to 2 and hide Group one.
And as soon as they are valid it will set the state to ‘2’ and show your next group where you can repeat the process.
At the end you can submit all your valid fields to the DB.
Hope that make sense… this way if someone decides to give up half way you dont have to remove all the invalid data.