1.2 KiB
Legacy form live validation
backend/static/js/components/liveValidationHandler.js provides client-side
validation for server-rendered Django forms. It is not used as the authorization
or data-integrity boundary; Django forms and DRF serializers must repeat every
required validation rule.
import { initLiveValidation } from './liveValidationHandler.js';
const validation = initLiveValidation({
formSelector: '#registrationForm',
debounce: 500,
rules: {
email: [
{ type: 'required', message: 'Email обязателен' },
{ type: 'email', message: 'Некорректный email' }
]
}
});
Supported rule types are required, email, pattern, minLength,
maxLength, match, anyContact and a custom validate function. Options
control validation on input, blur and submit.
The returned object exposes validateField, validateForm, clearValidation
and destroy. Call destroy when replacing a form dynamically to avoid duplicate
listeners.
The module applies Bootstrap is-valid, is-invalid and invalid-feedback
classes. New Next.js forms should use their component-level validation and API
errors instead of importing this legacy browser module.