Form Validation
Dile Components validate your forms in the browser before the data reaches the server: required
fields, impossible values and a complete set of rules (email, minLength,
between, same, files, IBAN...), with live validation, messages in English
and Spanish, and client and server errors shown in the same way.
Three layers, load only what you need
The first two layers come with @dile/ui. Add @dile/validation to the forms
that need rules.
Fields with the required attribute must have a value, in any
DileForm and in plain HTML forms.
Each field reports what only it can detect: an impossible date, an incomplete mask, an invalid phone number, a text that is not an amount...
More than 30 rules inspired by Laravel, custom and asynchronous rules, and live validation while the user types.
Try it
A form with DileFormValidation. Errors are checked as soon as you leave a field and
disappear as soon as you fix them.
class SignupForm extends DileFormValidation(DileForm(LitElement)) {
static validations = {
email: 'email|maxLength:120',
age: 'integer|between:18,120',
password: 'minLength:8',
password_confirmation: 'same:password',
};
// render() the fields with name="email", name="age"...
}
const { valid, errors } = await form.validate();
What you get
Laravel-style rules written as strings ( required|email|maxLength:120), arrays or objects, in the field, the form class or a schema.Live validation in eager,blur,inputorsubmitmode, with debounce and automatic dependencies between fields.English and Spanish messages out of the box, customizable per form, per field or for the whole application. File and image rules: type, size and image dimensions, for dile-drop-file.Same errors as the server: { field: message }, so client and server errors look the same.Integrated in the CRUD: insert, update, actions and multi-step forms validate before sending. Accessible: the first invalid field gets the focus, even inside collapsed containers, tabs or accordions.
Guides and reference
Getting started
Rules
-
Declaring Rules Where the validation rules of a field come from (attribute, static property or schema), their string and array syntax, array fields and conditional rules. -
Rules Reference Every built-in rule of @dile/validation (required, email, url, numbers, lengths, patterns, comparisons, files and images) plus the Spanish and banking rules.
Behavior
-
Live Validation Validate fields while the user fills the form, with the eager, blur, input and submit modes, debounce for slow rules and automatic dependencies between fields. -
Messages and Languages Validation messages in English and Spanish, how the language is chosen, and how to customize the texts per form, per field or for the whole application.
Integrations
-
Validation in the CRUD How the @dile/crud components validate their forms before sending, declare rules per insert, update and action in the resource configuration, and show the server errors. -
Validating Data Without a Form Use the Validator class of @dile/validation to validate plain objects or single values, in tests, services or components that are not forms.
Customization
-
Custom Rules Add your own validation rules for the whole application or for a single form, with messages by language, parameters and asynchronous checks against the server. -
Validation in Your Own Fields The contract that lets any element take part in the validation (required, isEmpty and getValidationError), field wrappers and native form support.
dile-components