OrchardCore icon indicating copy to clipboard operation
OrchardCore copied to clipboard

Client-side validation of the form elements

Open domonkosgabor opened this issue 4 years ago • 1 comments

In Orchard 1.x, you have the ability to add validation rules to form elements when building the form. For example, you can have the required, minimum and max length attributes, use a custom validation message and decide to show a custom validation message instead. We can also add a regular expression here too.

In Orchard Core, you cannot have validation for the input fields in this way when using the OrchardCore.Forms module. One solution is to use a ViewModel with attributes that come from the System.ComponentModel.DataAnnotations namespace and when the form has been submitted, you can check the ModelStateDictionary for errors using the IsValid property.

.NET Core uses the jQuery Unobtrusive Validation script to prevent submissions until the form is valid, ergo, it's the recommended way to use client-side validation. We could also provide a way for users to turn on/off the client-side validation for every input elements, that has validation enabled to prevent an unnecessary form post to a server and have a better user experience when working with forms.

domonkosgabor avatar Jul 28 '19 19:07 domonkosgabor