| 123456789101112131415161718192021222324252627282930 |
- import { computed } from 'vue'
- import type { ComputedRef } from 'vue'
- import * as _ from 'lodash-es'
- 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 _.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
- */
- function updateViolationState(field: string) {
- useFormStore().setViolations(
- _.omit(useFormStore().violations, field) as string[],
- )
- }
- return {
- fieldViolations,
- updateViolationState,
- }
- }
|