assembly/composables/useValidation.ts

18 lines
472 B
TypeScript
Raw Permalink Normal View History

2021-07-26 22:19:20 +00:00
import { computed } from "@nuxtjs/composition-api";
export function useValidation(errorsRef) {
const errorMessages = computed(() =>
Object.values(errorsRef.value)
.filter(({ message, show }) => !!message && show)
.map(({ message }) => message)
);
const isValid = computed(() =>
Object.values(errorsRef.value).every(
({ message, messageOnly }) => message === null || messageOnly === true
)
);
return { errorMessages, isValid };
}