fix autocomplete con workaround
This commit is contained in:
parent
4c7998f349
commit
58d73b6631
@ -31,23 +31,31 @@
|
|||||||
optionLabel="descrizione"
|
optionLabel="descrizione"
|
||||||
optionValue="codice"
|
optionValue="codice"
|
||||||
[filter]="true"></p-dropdown>
|
[filter]="true"></p-dropdown>
|
||||||
|
<!-- {{vm.filteredLuoghiEsteso | json}}
|
||||||
<p-autoComplete formControlName="luogo"
|
{{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"
|
[suggestions]="vm.filteredLuoghiEsteso"
|
||||||
(completeMethod)="fetchLuogo($event, 1)"
|
(completeMethod)="fetchLuogo($event, 1)"
|
||||||
(onSelect)="state.set({ filteredLuoghiEsteso: [] })"
|
(onSelect)="state.set({ filteredLuoghiEsteso: [] })"
|
||||||
|
(onHide)="checkLuogo()"
|
||||||
styleClass="w-full"
|
styleClass="w-full"
|
||||||
inputStyleClass="w-full"
|
inputStyleClass="w-full"
|
||||||
placeholder="Cerca per città, provincia, stato o regione"
|
placeholder="Cerca per città, provincia, stato o regione"
|
||||||
appendTo="body"
|
appendTo="body"
|
||||||
minLength="3"
|
minLength="1"
|
||||||
delay="500"
|
[delay]="500"
|
||||||
[forceSelection]="true"
|
emptyMessage="Nessun luogo trovato"
|
||||||
[showClear]="false"
|
[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"
|
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
|
<ng-template let-luogo
|
||||||
pTemplate="item">
|
#item>
|
||||||
<div class="flex align-items-center">
|
<div class="flex align-items-center">
|
||||||
@if (luogo.tipo === 'comune') {
|
@if (luogo.tipo === 'comune') {
|
||||||
<fa-icon class="fs-16 mr-3 text-color-secondary"
|
<fa-icon class="fs-16 mr-3 text-color-secondary"
|
||||||
@ -136,7 +144,7 @@
|
|||||||
</form>
|
</form>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
class="bg-surface-50 dark:bg-surface-900 rounded-2xl border-2 border-dashed border-surface-200 dark:border-surface-700 h-[450px]">
|
class="bg-surface-50 dark:bg-surface-900 rounded-2xl border-2 border-dashed border-surface-200 dark:border-surface-700 h-[400px]">
|
||||||
<google-map #gmap
|
<google-map #gmap
|
||||||
height="100%"
|
height="100%"
|
||||||
width="100%"
|
width="100%"
|
||||||
@ -160,6 +168,9 @@
|
|||||||
currentPageReportTemplate="Strutture {first} - {last} di {totalRecords}"
|
currentPageReportTemplate="Strutture {first} - {last} di {totalRecords}"
|
||||||
[paginator]="true"
|
[paginator]="true"
|
||||||
[rows]="10"
|
[rows]="10"
|
||||||
|
[autoLayout]="false"
|
||||||
|
responsiveLayout="stack"
|
||||||
|
scrollHeight="400px"
|
||||||
[rowsPerPageOptions]="[10, 50, 100]"
|
[rowsPerPageOptions]="[10, 50, 100]"
|
||||||
[globalFilterFields]="['struttura.nome']">
|
[globalFilterFields]="['struttura.nome']">
|
||||||
<ng-template #caption>
|
<ng-template #caption>
|
||||||
@ -204,7 +215,7 @@
|
|||||||
<p-rating *ngIf="row.struttura.stelline.length"
|
<p-rating *ngIf="row.struttura.stelline.length"
|
||||||
[(ngModel)]="row.struttura.stelline.length"
|
[(ngModel)]="row.struttura.stelline.length"
|
||||||
[readonly]="true" />
|
[readonly]="true" />
|
||||||
<span class="font-light"> {{ row.struttura.nome }}</span>
|
<span class="font-light"> <b>{{ row.struttura.nome }}</b></span>
|
||||||
<div *ngIf="row.struttura.sitoWeb"
|
<div *ngIf="row.struttura.sitoWeb"
|
||||||
class="mt-4 ont-light">
|
class="mt-4 ont-light">
|
||||||
<a class="cursor-pointer hover:underline text-primary-600"
|
<a class="cursor-pointer hover:underline text-primary-600"
|
||||||
|
|||||||
@ -66,7 +66,7 @@ export type cercaStruttureFormValue = cercaStruttureForm['value'];
|
|||||||
export interface CercaStruttureComponentState {
|
export interface CercaStruttureComponentState {
|
||||||
strutture: StrutturePubblicheResDto[];
|
strutture: StrutturePubblicheResDto[];
|
||||||
tipologieStrutture: TipoStruttura[];
|
tipologieStrutture: TipoStruttura[];
|
||||||
filteredLuoghiEsteso: LuogoRes[];
|
filteredLuoghiEsteso: Array<LuogoRes & { dataKey: string }>;
|
||||||
|
|
||||||
cercaStruttureFormSubmitted: boolean;
|
cercaStruttureFormSubmitted: boolean;
|
||||||
tipologieStruttureAreLoading: boolean;
|
tipologieStruttureAreLoading: boolean;
|
||||||
@ -125,6 +125,8 @@ export class StrutturePubblicheComponent {
|
|||||||
faHospital = faHospital;
|
faHospital = faHospital;
|
||||||
struttureConCoords: StrutturePubblicheResDto[] = [];
|
struttureConCoords: StrutturePubblicheResDto[] = [];
|
||||||
|
|
||||||
|
modelLuogo!: LuogoRes | null;
|
||||||
|
|
||||||
cols: TableColumn[] = [
|
cols: TableColumn[] = [
|
||||||
{
|
{
|
||||||
header: 'Strutture',
|
header: 'Strutture',
|
||||||
@ -185,13 +187,23 @@ export class StrutturePubblicheComponent {
|
|||||||
event: { originalEvent: Event; query: string },
|
event: { originalEvent: Event; query: string },
|
||||||
flagAttivo?: number,
|
flagAttivo?: number,
|
||||||
) {
|
) {
|
||||||
|
if (!event.query || event.query.length < 3) {
|
||||||
|
this.state.set({ filteredLuoghiEsteso: [] });
|
||||||
|
return;
|
||||||
|
}
|
||||||
const fetchCities$ = this.strutturePubblicheService
|
const fetchCities$ = this.strutturePubblicheService
|
||||||
.getLuoghiEsteso(event.query, flagAttivo)
|
.getLuoghiEsteso(event.query, flagAttivo)
|
||||||
.pipe(
|
.pipe(
|
||||||
catchError((err) => {
|
catchError((err) => {
|
||||||
return of(null);
|
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$);
|
this.state.connect(fetchCities$);
|
||||||
}
|
}
|
||||||
@ -422,4 +434,13 @@ export class StrutturePubblicheComponent {
|
|||||||
url = `${url}&travelmode=${travelMode}`;
|
url = `${url}&travelmode=${travelMode}`;
|
||||||
window.open(url, '_blank');
|
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