| 1234567891011121314151617181920212223242526272829 |
- import { computed } from 'vue'
- import type { ComputedRef } from 'vue'
- import { useFormStore } from '~/stores/form'
- /**
- * Composable pour gérer l'apparition de message d'erreurs de validation d'un champ de formulaire
- *
- * @param field
- */
- export function useFieldViolation(field: string) {
- const fieldViolations: ComputedRef<string> = computed(() => {
- return useFormStore().violations?.[field] ?? ''
- })
- /**
- * Lorsque la valeur d'un champ change, on supprime le fait qu'il puisse être "faux" dans le store
- * @param field
- */
- function updateViolationState(field: string) {
- const { [field]: _, ...fieldViolations } = useFormStore().violations
- useFormStore().setViolations(fieldViolations as string[])
- }
- return {
- fieldViolations,
- updateViolationState,
- }
- }
|