Skip to content
Snippets Groups Projects
Commit 85e2f552 authored by Konrad Mohrfeldt's avatar Konrad Mohrfeldt :koala:
Browse files

feat: add support for static error-state in FormGroup

This is helpful if the FormGroup is used as a container for other fields
which may have errors but the root FormGroup is used for propagating a
save state.
parent b637064d
No related branches found
No related tags found
No related merge requests found
...@@ -38,12 +38,7 @@ ...@@ -38,12 +38,7 @@
<slot name="iconLeft" :class="[iconClasses, 'tw-ml-2']" role="presentation" /> <slot name="iconLeft" :class="[iconClasses, 'tw-ml-2']" role="presentation" />
<slot name="iconRight" :class="[iconClasses, 'tw-mr-2']" role="presentation" /> <slot name="iconRight" :class="[iconClasses, 'tw-mr-2']" role="presentation" />
</div> </div>
<div <div v-if="errors !== undefined" :id="errorsId" class="invalid-feedback tw-block">
v-if="hasErrors"
:id="errorsId"
class="invalid-feedback"
:class="{ 'tw-block': hasErrors }"
>
<template v-for="(error, index) in errorList" :key="index"> <template v-for="(error, index) in errorList" :key="index">
<p class="last:tw-mb-0"> <p class="last:tw-mb-0">
{{ {{
...@@ -78,6 +73,7 @@ const props = withDefaults( ...@@ -78,6 +73,7 @@ const props = withDefaults(
label?: string label?: string
customControl?: boolean customControl?: boolean
errors?: undefined | (Error | undefined | null)[] errors?: undefined | (Error | undefined | null)[]
hasError?: boolean
withEditButton?: boolean withEditButton?: boolean
isSaving?: boolean | undefined isSaving?: boolean | undefined
center?: boolean center?: boolean
...@@ -88,6 +84,7 @@ const props = withDefaults( ...@@ -88,6 +84,7 @@ const props = withDefaults(
label: '', label: '',
errors: undefined, errors: undefined,
center: false, center: false,
hasError: false,
}, },
) )
const emit = defineEmits<{ const emit = defineEmits<{
...@@ -100,7 +97,7 @@ const formGroupClass = inject('formGroupClass', undefined) ...@@ -100,7 +97,7 @@ const formGroupClass = inject('formGroupClass', undefined)
const id = useId('form-group-control') const id = useId('form-group-control')
const errorsId = useId('form-group-errors') const errorsId = useId('form-group-errors')
const errorList = computed<Error[]>(() => (props.errors ?? []).filter((e): e is Error => !!e)) const errorList = computed<Error[]>(() => (props.errors ?? []).filter((e): e is Error => !!e))
const hasErrors = computed(() => errorList.value.length > 0) const hasErrors = computed(() => props.hasError || errorList.value.length > 0)
const iconClasses = 'tw-pointer-events-none tw-grid-area-cover tw-self-center' const iconClasses = 'tw-pointer-events-none tw-grid-area-cover tw-self-center'
const controlAttributes = computed(() => ({ const controlAttributes = computed(() => ({
class: [ class: [
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment