| 12345678910111213141516171819202122232425262728 |
- import {computed, ComputedRef} from "@vue/reactivity";
- 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<string> = 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
- * @param field
- * @param value
- */
- function updateViolationState(field: string, value: any) {
- //@ts-ignore
- useFormStore().setViolations(useOmit(useFormStore().violations, field))
- }
- return {
- fieldViolations,
- updateViolationState: (fieldValue: any) => updateViolationState(fieldValue, field)
- }
- }
|