| 1234567891011121314151617181920212223242526272829303132 |
- import { AnyStore } from '~/types/interfaces'
- import {computed, ComputedRef} from "@nuxtjs/composition-api";
- /**
- * @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 error:ComputedRef<Boolean> = computed(()=>{
- return store.state.form.violations.indexOf(field) >= 0
- })
- /**
- * 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) {
- const errors = store.state.form.violations.filter((field:string) => field !== changeField)
- store.commit('form/setViolations', errors)
- emit('update', fieldValue, changeField)
- }
- return {
- onChange: (fieldValue:any) => onChange(emit, fieldValue, field),
- error
- }
- }
|