Skip to content

Commit c60a97c

Browse files
committed
Makes form's error message closable and makes it the same context as other elements for z-index to work.
1 parent bc52acb commit c60a97c

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

packages/web-forms/src/components/OdkWebForm.vue

+14-9
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import { initializeForm, type FetchFormAttachment, type RootNode } from '@getodk
88
import Button from 'primevue/button';
99
import Card from 'primevue/card';
1010
import PrimeMessage from 'primevue/message';
11-
import type { ComponentPublicInstance } from 'vue';
1211
import { computed, getCurrentInstance, provide, reactive, ref, watchEffect } from 'vue';
1312
import { FormInitializationError } from '../lib/error/FormInitializationError.ts';
1413
import FormLoadFailureDialog from './Form/FormLoadFailureDialog.vue';
@@ -105,6 +104,8 @@ const emit = defineEmits<OdkWebFormEmits>();
105104
106105
const odkForm = ref<RootNode>();
107106
const submitPressed = ref(false);
107+
const floatingErrorActive = ref(false);
108+
const showValidationError = ref(false);
108109
const initializeFormError = ref<FormInitializationError | null>();
109110
110111
initializeForm(props.formXml, {
@@ -125,18 +126,18 @@ const handleSubmit = () => {
125126
const root = odkForm.value;
126127
127128
if (root?.validationState.violations?.length === 0) {
129+
floatingErrorActive.value = false;
128130
// eslint-disable-next-line @typescript-eslint/no-floating-promises
129131
emitSubmit(root);
130132
// eslint-disable-next-line @typescript-eslint/no-floating-promises
131133
emitSubmitChunked(root);
132134
} else {
135+
floatingErrorActive.value = true;
133136
submitPressed.value = true;
134137
document.scrollingElement?.scrollTo(0, 0);
135138
}
136139
};
137140
138-
const validationErrorMessagePopover = ref<ComponentPublicInstance | null>(null);
139-
140141
provide('submitPressed', submitPressed);
141142
142143
const validationErrorMessage = computed(() => {
@@ -149,10 +150,10 @@ const validationErrorMessage = computed(() => {
149150
});
150151
151152
watchEffect(() => {
152-
if (submitPressed.value && validationErrorMessage.value) {
153-
(validationErrorMessagePopover.value?.$el as HTMLElement)?.showPopover?.();
153+
if (floatingErrorActive.value && validationErrorMessage.value?.length) {
154+
showValidationError.value = true;
154155
} else {
155-
(validationErrorMessagePopover.value?.$el as HTMLElement)?.hidePopover?.();
156+
showValidationError.value = false;
156157
}
157158
});
158159
</script>
@@ -186,8 +187,9 @@ watchEffect(() => {
186187
:class="{ 'submit-pressed': submitPressed }"
187188
>
188189
<div class="form-wrapper">
189-
<div v-show="submitPressed && validationErrorMessage" class="error-banner-placeholder" />
190-
<PrimeMessage ref="validationErrorMessagePopover" popover="manual" severity="error" icon="icon-error_outline" class="form-error-message" :closable="false">
190+
<div v-if="showValidationError" class="error-banner-placeholder" />
191+
<!-- Closable error message to clear the view and avoid overlap with other elements -->
192+
<PrimeMessage v-if="showValidationError" severity="error" icon="icon-error_outline" class="form-error-message" @close="floatingErrorActive = false">
191193
{{ validationErrorMessage }}
192194
</PrimeMessage>
193195

@@ -266,6 +268,8 @@ watchEffect(() => {
266268
}
267269

268270
.form-error-message.p-message.p-message-error {
271+
position: fixed;
272+
z-index: 100;
269273
border-radius: 10px;
270274
background-color: var(--error-bg-color);
271275
border: 1px solid var(--error-text-color);
@@ -275,7 +279,7 @@ watchEffect(() => {
275279
top: 1rem;
276280

277281
:deep(.p-message-wrapper) {
278-
padding: 0.75rem 0.75rem;
282+
padding: 8px 15px;
279283
flex-grow: 1;
280284
}
281285

@@ -349,6 +353,7 @@ watchEffect(() => {
349353
margin: var(--wf-error-banner-gap) 1rem 0 1rem;
350354
max-width: unset;
351355
width: calc(100% - 2rem);
356+
top: 0.27rem;
352357
}
353358

354359
.questions-card {

0 commit comments

Comments
 (0)