Skip to content

Commit 05e12f4

Browse files
committed
Implements autosave when form submits for geopoint
1 parent 36ea1d1 commit 05e12f4

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,19 @@ initializeForm(props.formXml, {
121121
initializeFormError.value = new FormInitializationError(cause);
122122
});
123123
124+
type BeforeSubmitCallback = () => void;
125+
const beforeSubmitCallbacks: BeforeSubmitCallback[] = [];
126+
provide<(callback: BeforeSubmitCallback) => void>(
127+
'registerBeforeSubmit',
128+
(callback: BeforeSubmitCallback) => beforeSubmitCallbacks.push(callback)
129+
);
130+
124131
const handleSubmit = () => {
125132
const root = odkForm.value;
126133
127134
if (root?.validationState.violations?.length === 0) {
135+
// Run all registered beforeSubmit functions
136+
beforeSubmitCallbacks.forEach((callback) => callback());
128137
// eslint-disable-next-line @typescript-eslint/no-floating-promises
129138
emitSubmit(root);
130139
// eslint-disable-next-line @typescript-eslint/no-floating-promises

packages/web-forms/src/components/controls/Input/InputGeopoint.vue

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import type { GeopointInputNode } from '@getodk/xforms-engine';
33
import Button from 'primevue/button';
44
import PrimeProgressSpinner from 'primevue/progressspinner';
5-
import { computed, ref } from 'vue';
5+
import { inject, computed, ref } from 'vue';
66
77
interface Coordinates {
88
latitude: string;
@@ -101,6 +101,10 @@ const observer = new IntersectionObserver(
101101
{ threshold: 0.6 }
102102
);
103103
104+
const registerBeforeSubmit = inject<(callback: () => void) => void>('registerBeforeSubmit');
105+
// Autosave geopoint value before submitting the form.
106+
registerBeforeSubmit?.(() => save());
107+
104108
const start = () => {
105109
geoLocationError.value = false;
106110
if (watchID.value) {

0 commit comments

Comments
 (0)