Reputation: 6368
I am using PrimeNG from primefaces.org
Everything is working well. But I have a small problem. When using p-autoComplete
, when p-autoComplete
is focused it does not show suggestions. I mean I have to type something to get suggestions. I think it is the default behavior. But I want to change it.
What I have tried:
I have tried to set [minLength]="0"
, but no luck!!!!!!!!
Upvotes: 2
Views: 3799
Reputation: 1
You can go to the autocomplete.js file and add some code to onInputFocus like this
AutoComplete.prototype.onInputFocus = function (event) {
this.focus = true;
var queryValue = this.multiple ? this.multiInputEL.nativeElement.value : this.inputEL.nativeElement.value;
if (this.dropdownMode === 'blank')
this.search(event, '');
else if (this.dropdownMode === 'current')
this.search(event, queryValue);
this.onDropdownClick.emit({
originalEvent: event,
query: queryValue
});
this.onFocus.emit(event);
};
you can right-click on p-autoComplete to get you there, beware of updates, when you update prime-ng you will have to do it again.
Upvotes: 0
Reputation: 41553
You need to set some default items in to the suggestions property as
<p-autoComplete [(ngModel)]="val" [suggestions]="results" field="name"></p-autoComplete>
and you should be using in component code
results = ['a', 'b']
When you are loading from service you need to either clear or append to same array
Upvotes: 0