fix autocomplete con workaround
This commit is contained in:
parent
4c7998f349
commit
0e6560c66d
@ -31,23 +31,31 @@
|
||||
optionLabel="descrizione"
|
||||
optionValue="codice"
|
||||
[filter]="true"></p-dropdown>
|
||||
|
||||
<p-autoComplete formControlName="luogo"
|
||||
<!-- {{vm.filteredLuoghiEsteso | json}}
|
||||
{{cercaStruttureForm.controls['luogo'].value | json}} -->
|
||||
<!-- <p-autocomplete [(ngModel)]="modelLuogo"
|
||||
[ngModelOptions]="{ standalone: true }"
|
||||
[suggestions]="vm.filteredLuoghiEsteso"
|
||||
(completeMethod)="fetchLuogo($event, 1)"
|
||||
optionLabel="tipo" /> -->
|
||||
<p-autoComplete #acSt formControlName="luogo"
|
||||
[suggestions]="vm.filteredLuoghiEsteso"
|
||||
(completeMethod)="fetchLuogo($event, 1)"
|
||||
(onSelect)="state.set({ filteredLuoghiEsteso: [] })"
|
||||
(onHide)="checkLuogo()"
|
||||
styleClass="w-full"
|
||||
inputStyleClass="w-full"
|
||||
placeholder="Cerca per città, provincia, stato o regione"
|
||||
appendTo="body"
|
||||
minLength="3"
|
||||
delay="500"
|
||||
[forceSelection]="true"
|
||||
[showClear]="false"
|
||||
minLength="1"
|
||||
[delay]="500"
|
||||
emptyMessage="Nessun luogo trovato"
|
||||
[showClear]="true"
|
||||
class="flex-auto lg:flex-1 lg:mt-0 w-full mr-0 lg:mr-1 text-surface-900 dark:text-surface-0 lg:w-72"
|
||||
field="luogo">
|
||||
dataKey="dataKey"
|
||||
optionLabel="luogo">
|
||||
<ng-template let-luogo
|
||||
pTemplate="item">
|
||||
#item>
|
||||
<div class="flex align-items-center">
|
||||
@if (luogo.tipo === 'comune') {
|
||||
<fa-icon class="fs-16 mr-3 text-color-secondary"
|
||||
|
||||
@ -66,7 +66,7 @@ export type cercaStruttureFormValue = cercaStruttureForm['value'];
|
||||
export interface CercaStruttureComponentState {
|
||||
strutture: StrutturePubblicheResDto[];
|
||||
tipologieStrutture: TipoStruttura[];
|
||||
filteredLuoghiEsteso: LuogoRes[];
|
||||
filteredLuoghiEsteso: Array<LuogoRes & { dataKey: string }>;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user