Skip to content

Component Required Validation

Required validation can be added to components through the custom property required. This feature is applicable to various form components and supports different types of values.

This feature is internally implemented through custom property methods.

Data Structure

ts
type Required = boolean | string | {
    message ?: String; // Custom error message
    trigger ?: String; // Event that triggers validation, e.g., 'blur' or 'change'
    required ?: boolean; // Whether it is required
    validator ?: Function; // Custom validation function
}

Examples

Set input as required

Through simple required: true, you can add required validation to input components. When users do not fill in this field, form validation will fail.

Custom Error Message

You can customize the error message for required validation through required: 'Enter content'. This is very useful for multi-language support or when precise prompts are needed.

FormCreate is an open-source project released under the MIT License. Free for personal and commercial use.