diff --git a/src/src/app/modals/place-create-modal/place-create-modal.component.html b/src/src/app/modals/place-create-modal/place-create-modal.component.html index 199c632..e4f0c23 100644 --- a/src/src/app/modals/place-create-modal/place-create-modal.component.html +++ b/src/src/app/modals/place-create-modal/place-create-modal.component.html @@ -2,7 +2,8 @@
- + { + const category: Category | undefined = categories.find(c => c.name == r.category); + if (!category) return; + this.placeForm.get('category')?.setValue(category.id); + }}) + } + } + gmapsSearchText() { const query = this.placeForm.get('name')?.value; if (!query) return; this.apiService.gmapsSearchText(query).subscribe({ next: (results) => { + if (!results.length) { + this.utilsService.toast('warn', 'No result', 'No result available for this autocompletion'); + return; + } + if (results.length == 1) { - const r = results[0]; - this.placeForm.patchValue({ ...r, lat: formatLatLng(r.lat), lng: formatLatLng(r.lng), place: r.name || '' }); - this.placeForm.get('category')?.markAsDirty(); + this.gmapsToForm(results[0]) return; } @@ -235,14 +251,7 @@ export class PlaceCreateModalComponent { modal.onClose.pipe(take(1)).subscribe({ next: (result: GooglePlaceResult | null) => { if (!result) return; - const r = result; - this.placeForm.patchValue({ - ...r, - lat: formatLatLng(r.lat), - lng: formatLatLng(r.lng), - place: r.name || '', - }); - this.placeForm.get('category')?.markAsDirty(); + this.gmapsToForm(result); }, }); },