Comprehensive validation library for Vue.js applications providing common validators with built-in error messages and customization options
87
Build a user registration form that validates user input both on the client-side and integrates server-side validation errors. The form should display validation errors from both sources and allow users to clear server errors when they modify a field.
@generates
The form collects four fields: username, email, password, and confirm password. Implement client-side validation with these rules:
Username: Required, minimum 3 characters, maximum 20 characters
Email: Required, valid email format
Password: Required, minimum 8 characters
Confirm password: Required, must match the password field
When username is "ab", email is "test@example.com", password is "password123", and confirm is "password123", validation shows username minimum length error @test
When the form is submitted, if client-side validation passes, call the validateOnServer(formData) function. This function returns server-side validation errors in the format { fieldName: [errorMessage] }. These errors should be integrated into the validation state and displayed alongside client-side errors.
The mock server validation function is:
async function validateOnServer(formData) {
await new Promise(resolve => setTimeout(resolve, 500));
const errors = {};
if (formData.username === 'admin' || formData.username === 'root') {
errors.username = ['This username is reserved'];
}
if (formData.email && formData.email.endsWith('@blocked.com')) {
errors.email = ['Email domain is not allowed'];
}
return Object.keys(errors).length > 0 ? errors : null;
}When a user modifies a field that has a server-side error, that server-side error should be cleared while preserving any client-side validation errors.
/**
* Creates a registration form with validation
* @returns {Object} Object containing formData (reactive form values) and v$ (validation state)
*/
export function createRegistrationForm();
/**
* Submits the form and integrates server validation results
* @param {Object} v$ - The validation state object
* @param {Object} formData - The form data object
* @returns {Promise<boolean>} True if submission succeeds (no errors), false otherwise
*/
export async function submitForm(v$, formData);Provides core validation functionality and state management.
Provides built-in validators for common validation rules.
Install with Tessl CLI
npx tessl i tessl/npm-vuelidate--validatorsdocs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10