From 0e6560c66df19e41d7b866c50eb630424a0e0f01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Flavio=20Bont=C3=A0?= Date: Thu, 13 Nov 2025 16:27:42 +0100 Subject: [PATCH] fix autocomplete con workaround --- .../strutture-pubbliche.component.html | 24 ++++++++++++------ .../strutture-pubbliche.component.ts | 25 +++++++++++++++++-- 2 files changed, 39 insertions(+), 10 deletions(-) diff --git a/src/app/modules/public/strutture-pubbliche/strutture-pubbliche.component.html b/src/app/modules/public/strutture-pubbliche/strutture-pubbliche.component.html index fd85992..f825aee 100644 --- a/src/app/modules/public/strutture-pubbliche/strutture-pubbliche.component.html +++ b/src/app/modules/public/strutture-pubbliche/strutture-pubbliche.component.html @@ -31,23 +31,31 @@ optionLabel="descrizione" optionValue="codice" [filter]="true"> - - + + + dataKey="dataKey" + optionLabel="luogo"> + #item>
@if (luogo.tipo === 'comune') { ; cercaStruttureFormSubmitted: boolean; tipologieStruttureAreLoading: boolean; @@ -125,6 +125,8 @@ export class StrutturePubblicheComponent { faHospital = faHospital; struttureConCoords: StrutturePubblicheResDto[] = []; + modelLuogo!: LuogoRes | null; + cols: TableColumn[] = [ { header: 'Strutture', @@ -185,13 +187,23 @@ export class StrutturePubblicheComponent { event: { originalEvent: Event; query: string }, flagAttivo?: number, ) { + if (!event.query || event.query.length < 3) { + this.state.set({ filteredLuoghiEsteso: [] }); + return; + } const fetchCities$ = this.strutturePubblicheService .getLuoghiEsteso(event.query, flagAttivo) .pipe( catchError((err) => { return of(null); }), - map((res) => ({ filteredLuoghiEsteso: res?.rows })), + map((res) => ({ + filteredLuoghiEsteso: + res?.rows.map((res) => ({ + ...res, + dataKey: res.tipo + ' → ' + res.luogo, + })) ?? [], + })), ); this.state.connect(fetchCities$); } @@ -422,4 +434,13 @@ export class StrutturePubblicheComponent { url = `${url}&travelmode=${travelMode}`; window.open(url, '_blank'); } + + checkLuogo() { + //Hack: rimosso dall'autocomplete forceSelection perchè non funzionava come previsto, selezionando ad esempio "Milano" (comune), selezionava "Milano" (comune). + const luogo = this.cercaStruttureForm.controls['luogo'].value; + console.log('luogo', luogo); + if (typeof luogo === 'string') { + this.cercaStruttureForm.controls['luogo'].setValue(null); + } + } }