Skip to content

Commit 147c4be

Browse files
committed
only cache request if no empty
1 parent 883a086 commit 147c4be

File tree

2 files changed

+28
-8
lines changed

2 files changed

+28
-8
lines changed

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

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,8 @@ const emit = defineEmits<OdkWebFormEmits>();
169169
const getLocation = async (): Promise<string> => {
170170
let point = '';
171171
try {
172-
point = await geolocationService.getBestGeopoint();
173172
geolocationErrorMessage.value = '';
173+
point = await geolocationService.getBestGeopoint();
174174
} catch {
175175
// TODO: translations
176176
geolocationErrorMessage.value =
@@ -233,8 +233,8 @@ const validationErrorMessage = computed(() => {
233233
234234
// TODO: translations
235235
if (violationLength === 0) return '';
236-
else if (violationLength === 1) return '1 question with error';
237-
else return `${violationLength} questions with errors`;
236+
else if (violationLength === 1) return '1 question with error.';
237+
else return `${violationLength} questions with errors.`;
238238
});
239239
240240
watchEffect(() => {
@@ -289,8 +289,10 @@ onUnmounted(() => {
289289
@close="floatingErrorActive = false"
290290
>
291291
<IconSVG name="mdiAlertCircleOutline" variant="error" />
292-
<span v-if="validationErrorMessage?.length">{{ validationErrorMessage }}</span>
293-
<span v-if="geolocationErrorMessage?.length">{{ geolocationErrorMessage }}</span>
292+
<span class="form-error-text-wrap">
293+
<span v-if="validationErrorMessage?.length">{{ validationErrorMessage }}</span>
294+
<span v-if="geolocationErrorMessage?.length">{{ geolocationErrorMessage }}</span>
295+
</span>
294296
</Message>
295297

296298
<FormHeader :form="state.root" />
@@ -386,6 +388,11 @@ onUnmounted(() => {
386388
.odk-icon {
387389
margin-right: 10px;
388390
}
391+
392+
.form-error-text-wrap {
393+
display: flex;
394+
flex-direction: column;
395+
}
389396
}
390397
}
391398

packages/xforms-engine/src/instance/PrimaryInstance.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -296,8 +296,21 @@ export class PrimaryInstance<
296296
return Promise.resolve(result);
297297
}
298298

299-
getBackgroundGeopoint() {
300-
this.backgroundGeopoint ??= this.geolocationProvider?.getLocation() ?? Promise.resolve('');
301-
return this.backgroundGeopoint;
299+
async getBackgroundGeopoint() {
300+
if (this.backgroundGeopoint != null) {
301+
return await this.backgroundGeopoint;
302+
}
303+
304+
try {
305+
this.backgroundGeopoint = this.geolocationProvider?.getLocation() ?? Promise.resolve('');
306+
const result = await this.backgroundGeopoint;
307+
if (!result.length) {
308+
this.backgroundGeopoint = null;
309+
}
310+
return result;
311+
} catch {
312+
this.backgroundGeopoint = null;
313+
return '';
314+
}
302315
}
303316
}

0 commit comments

Comments
 (0)