I was working on a form for a timekeeping app, where a user is able to enter their time worked, as well as breaks taken.
There is no limit on the amount of breaks that may be taken, but one of the validation requirements is that no two breaks may overlap.
Here’s how I implemented this validation check.
Consider this scenario:
You have a form which submits to itself (e.g. a simple contact form). The first time it loads you don’t want to do anything other that render the form.
However, when a user hits “Submit”, you want to process whatever data you have received, then re-render the form, including (for example) error messages where appropriate.