import { AnyStore } from '~/types/interfaces' import {computed, ComputedRef} from "@nuxtjs/composition-api"; import * as _ from 'lodash' /** * @category composables/form * Composable pour gérer l'apparition de message si le formulaire est dirty * @param field * @param emit * @param store */ export function useError(field: string, emit: any, store: AnyStore){ const violation:ComputedRef = computed(()=>{ return _.get(store.state.form.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) { store.commit('form/setViolations', _.omit(store.state.form.violations, changeField)) emit('update', fieldValue, changeField) } return { onChange: (fieldValue:any) => onChange(emit, fieldValue, field), violation } }