Enabling a submit option based on the form state
In this recipe, we dive into a strategy to enhance the user experience by dynamically controlling the state of the form’s submit button. We use forms not only when creating a new object but also when modifying an existing one as well. It makes sense that we would prevent the form submission when a user didn’t make any changes or if some input is invalid. Having that feature in place, we improve the user experience, conserve memory usage, and reduce unnecessary server requests.
Let’s enhance a form with a mechanism that enables form saving only when there have been changes to the form data and all inputs are valid.
Getting ready
Before making the form submit button react to the form state, do the following:
- Create a
Chapter07
/Recipe07
directory – this will be your working directory - Copy
Event
,EventLocation
,EventManager
,EventNameValidationAttribute
,TypeValidationClassProvider
, andValidationToast...