| 123456789101112131415161718192021222324252627282930 |
- import {computed} from "@vue/reactivity";
- import type {ComputedRef} from "@vue/reactivity";
- import {useFormStore} from "~/stores/form";
- import * as _ from 'lodash-es'
- /**
- * 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 _.get(useFormStore().violations, field, '')
- })
- /**
- * Lorsque la valeur d'un champ change, on supprime le fait qu'il puisse être "faux" dans le store
- * @param field
- * @param value
- */
- function updateViolationState(field: string, value: any) {
- //@ts-ignore
- useFormStore().setViolations(_.omit(useFormStore().violations, field))
- }
- return {
- fieldViolations,
- updateViolationState: (fieldValue: any) => updateViolationState(fieldValue, field)
- }
- }
|