autocomplete with feature for new-tags
I'm submitting a ... (check one with "x")
[ ] bug report => Search github for a similar issue or PR before submitting
[x] feature request => Please check if request is not on the roadmap already https://github.com/primefaces/primeng/wiki/Roadmap
[ ] support request => Please do not submit support request here, instead see http://forum.primefaces.org/viewforum.php?f=35
Plunkr Case (Bug Reports) Please fork the plunkr below and create a case demonstrating your bug report. Issues without a plunkr have much less possibility to be reviewed.
No plunker
Current behavior The autocomplete now only adds tags which are existing in the defined list returned from the service. If it doesn't exist - p-autocomplete will not allow that tag to be added
Expected behavior Have another @Input tag flag value which lets users add non-existing tags into the component. E.g. @Input allowNonExisting which when
- true: allows for users to add non-existing tags (which aren't present in the results returned by the service to be added)
- false: continues with the current behavior, which is not letting the user add a tag which isn't present in the results returned by the service.
Minimal reproduction of the problem with instructions Not a bug, but I have a workaround using @ViewChild which can let me add new tags not present into the p-autocomplete component. Let me know if you would like to see that.
What is the motivation / use case for changing the behavior? Letting users add new tags which can be then added to the database.
Please tell us about your environment: OS - MacOS Sierra IDE - Webstorm Package manager - npm http server - nginx
-
Angular version: 2.4.0
-
PrimeNG version: 2.0.6
-
Browser: [all]
-
Language: [TypeScript 2.0]
-
Node (for AoT issues):
node --version= 7.8
@dixitk13 Hi, can you tell me how you solved this?
@dixitk13 Can you show us your workaround?
I used a ViewChild to get to the specific element of the autoComplete. Looks a little ugly but it works for my use-case.
The way it works is, getLabels service gets the specific labels available via a service call. If the event.query doesn't exist in it: its a new label.
This new label can be added to the viewChild's value which makes it visible.
public search(event: any): void {
this.subService.getLabels(event.query)
.then(data => {
if(data) data = data.filter(x => x.toLowerCase().includes(event.query.toLowerCase()));
if(data && data.length == 0) this.newData = event.query;
else this.newData = null;
this.results = data;
});
}
I've used a keydown.enter event for trigger the logic (which is very un-intuitive in my opinion, but feel free to change that).
public onBlur(event: any): void {
if(this.newData && this.autoComplete && this.autoComplete.value){
this.autoComplete.value = [...this.autoComplete.value, this.newData];
this.newData = null;
this.autoComplete.multiInputEL.nativeElement.value = '';
}else if(this.newData){
this.autoComplete.value = [this.newData];
this.newData = null;
this.autoComplete.multiInputEL.nativeElement.value = '';
}
}
And finally the html markup
<p-autoComplete [(ngModel)]="text" #autoComplete
[placeholder]="'Select Labels'"
[suggestions]="results" [multiple]="true"
(keydown.enter)="onBlur($event)"
(completeMethod)="search($event)"></p-autoComplete>
Hi,
So sorry for the delayed response! Improvements have been made to many components recently, both in terms of performance and enhancement. Therefore, this improvement may have been developed in another issue ticket without realizing it. You can check this in the documentation. If there is no improvement on this, can you reopen the issue so we can include it in our roadmap? Please don't forget to add your feedback as a comment after reopening the issue. These will be taken into account by us and will contribute to the development of this feature. Thanks a lot for your understanding!
Best Regards,
Nope, this feature is not implemented yet.
This development has never been done. Can someone explain why it's completed? Or should we continue by using one workaround like https://github.com/primefaces/primeng/issues/608#issuecomment-1564458809 ?