import { AnyStore } from '~/types/interfaces' import {ComputedRef} from "@vue/reactivity"; import {useFormStore} from "~/store/form"; /** * Composable pour gérer l'apparition de message d'erreurs de validation d'un champ de formulaire * * @param field * @param emit */ export function useFieldViolation(field: string, emit: any){ const violation: ComputedRef = computed(()=>{ return useGet(useFormStore().violations, field, '') }) /** * Lorsque la valeur d'un champ change, on supprime le fait qu'il puisse être "faux" dans le store, et on émet sa nouvelle valeur au parent * @param emit * @param fieldValue * @param changeField */ function onChange (emit:any, fieldValue:any, changeField:string) { //@ts-ignore useFormStore().setViolations(useOmit(useFormStore().violations, changeField)) emit('update', fieldValue, changeField) } return { onChange: (fieldValue:any) => onChange(emit, fieldValue, field), violation } }