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 = 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, } }