Skip to content

Component Required Validation

Add required validation 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

Use required: true to add required validation to input components. When users don't fill in this field, form validation fails.

Custom Error Message

Customize the error message for required validation through required: 'Enter content'. This is 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.