import { Validation } from '@vuelidate/core'; import { Ref } from 'vue'; type FormValidationStatus = 'error' | 'warning' | 'success'; /** * Options for validators. */ interface ValidatorOptions { /** * Options for the required validator. * Use either `label` or `msg`, but not both. */ required?: { label?: never; msg: string; validationStatus?: FormValidationStatus; } | { label: string; msg?: never; validationStatus?: FormValidationStatus; }; /** * Options for the maxLength validator. * Use either `label` and `value`, or `msg`, but not both. */ maxLength?: { label?: never; value?: never; msg: string; validationStatus?: FormValidationStatus; } | { label: string; value: number; msg?: never; validationStatus?: FormValidationStatus; }; /** * Options for the maxLength validator. * Use either `label` and `value`, or `msg`, but not both. */ minLength?: { label?: never; value?: never; msg: string; validationStatus?: FormValidationStatus; } | { label: string; value: number; msg?: never; validationStatus?: FormValidationStatus; }; /** * Options for the minValue validator. * Use either `label` and `value`, or `msg`, but not both. */ minValue?: { label?: never; value?: never; msg: string; validationStatus?: FormValidationStatus; } | { label: string; value: number; msg?: never; validationStatus?: FormValidationStatus; }; /** * Options for the maxValue validator. * Use either `label` and `value`, or `msg`, but not both. */ maxValue?: { label?: never; value?: never; msg: string; validationStatus?: FormValidationStatus; } | { label: string; value: number; msg?: never; validationStatus?: FormValidationStatus; }; /** * Options for the unique validator. * Use either `label` or `msg`, but not both. */ unique?: { label?: never; msg: string; validationStatus?: FormValidationStatus; } | { label: string; msg?: never; validationStatus?: FormValidationStatus; }; } interface ValidatorOptions { required?: { label?: never; msg: string; validationStatus?: FormValidationStatus; } | { label: string; msg?: never; validationStatus?: FormValidationStatus; }; maxLength?: { label?: never; value?: never; msg: string; validationStatus?: FormValidationStatus; } | { label: string; value: number; msg?: never; validationStatus?: FormValidationStatus; }; minLength?: { label?: never; value?: never; msg: string; validationStatus?: FormValidationStatus; } | { label: string; value: number; msg?: never; validationStatus?: FormValidationStatus; }; minValue?: { label?: never; value?: never; msg: string; validationStatus?: FormValidationStatus; } | { label: string; value: number; msg?: never; validationStatus?: FormValidationStatus; }; maxValue?: { label?: never; value?: never; msg: string; validationStatus?: FormValidationStatus; } | { label: string; value: number; msg?: never; validationStatus?: FormValidationStatus; }; unique?: { label?: never; msg: string; validationStatus?: FormValidationStatus; } | { label: string; msg?: never; validationStatus?: FormValidationStatus; }; } type FieldOptions
= { [K in keyof Form]?: ValidatorOptions; }; /** * Bind validation options to a form. * * @template Form - The type of the form. * @param {Ref} v - The validation reference. * @param {FieldOptions} [options] - The field options for validation. * @returns {object} - An object containing the `bindValidation` function. * * @example * Example 1: * Bind validation options for Form with label-based configuration using default validation message * * const { bindValidation } = useBindValidation(v, { * name: { required: { label: labels.name } }, // Required validation with label * account: { required: { label: labels.account } }, // Required validation with label * status: { required: { label: labels.status } }, // Required validation with label * tags: { maxLength: { label: labels.tags, value: 5 } }, // MaxLength validation with label and value * }); * Example 2: * Bind validation options for Form with message-based configuration. * * const { bindValidation } = useBindValidation(v, { * name: { required: { msg: requiredMsg('name') } }, // Required validation with message * account: { required: { msg: requiredMsg('account') } }, // Required validation with message * status: { required: { msg: requiredMsg('status') } }, // Required validation with message * tags: { * maxLength: { * msg: t('canvasUI.CCreateTemplateModal.form.validation.maxLength', { * field: labels.tags.toLowerCase(), * value: TAGS_LIMIT, * }), * }, // MaxLength validation with message * }, * }); */ declare const _default: >(v: Ref, options?: FieldOptions) => { bindValidation: (key: Key) => { feedback: string; showFeedback: any; validationStatus: FormValidationStatus; }; }; export default _default;