how to add other value to the input AutoComplete Multiple ?
I want to use it like a tags input autocompete . But when I use the input AutoComplete Multiple of primeFace , I just enter defaut value text (what I config in code before ) , can't pass my text to the input AutoComplete Multiple . Thanks for any help .
@ducduongtmb did you find anything about it? because i want to use tag based dropdown as well
also interested in a solution to this ('Tag input with autocomplete AND "add new" option'):
- 'AutoComplete' doesn't allow for adding new values
- 'Chips' doesn't have an autocomplete for existing values
Hi,
I would like to use autocomplete multi with support for adhoc strings aswell. Is it possible?
@elega9t
@schellmax
Hi Guys,
It is possible to add new values as chips in autocomplete multi. I have created a custom component with the help of chips and autocomplete components and its working fine for me. So you can also try to merge these two features in a single component or if you still need that feature then i can share my components with you guys. Just let me know in such case.
@sourabh8003
Wow, thats great news. Do you mind creating a github sample project and share your component.
Thanks
@elega9t
Sure
Hi guys,
@elega9t @ducduongtmb @ducduongtmb
Currently i am working on a downstream repository of prineNg. It will take some time so for now you can use below code to add new values in autocomplete with chips, tab click also adds chips. Follow the steps below and in case of any issue reply me:
Step 1> update the paths with your node_module folder path with primeNg in the include file
import {InputTextModule} from '../../../../node_modules/primeng/components/inputtext/inputtext'; import {ButtonModule} from '../../../../node_modules/primeng/components/button/button'; import { ttTooltipModule } from './tt-tooltip.directive'; import {SharedModule, PrimeTemplate} from '../../../../node_modules/primeng/components/common/shared'; import {DomHandler} from '../../../../node_modules/primeng/components/dom/domhandler';
Step 2> Import the custom autocomplete module "SAutocompleteWithChipsModule" in your module.
Step 3> use the compnent with the primeNg's original attributes but with new selector "s-autoComplete"
<s-autoComplete [(ngModel)]="text" [suggestions]="results" (completeMethod)="search($event)">
Then Enjoy!
My solution for having an autocomplete component (for multiple tags) with the the possibility of adding custom texts was using the onKeyUp-event. I've implemented an event handler that adds my custom text to the list, each time I press the Enter key.
Code sample: https://stackblitz.com/edit/angular-kfvj5p
@doeringp : Kudos.. You saved my so many hours.... Thanks.
@doeringp : Thank you very much
@doeringp thanks, exactly what I have been looking for!
My solution for having an autocomplete component (for multiple tags) with the the possibility of adding custom texts was using the onKeyUp-event. I've implemented an event handler that adds my custom text to the list, each time I press the Enter key.
Code sample: https://stackblitz.com/edit/angular-kfvj5p @doeringp can you help in fixing the same with outside click event. I have to add the value when user enter some letters and clicks outside of the input field.
For those coming here from Google, here is a request to have this feature built in: https://github.com/primefaces/primeng/issues/3211
thanks!! nice job!! helpful for me, regards!
I used a similar approach listening for changes to the autoComplete's value and then adding the current value to the list of entries:
Template
<p-autoComplete (keyup)=inputChanged($event)" [suggestions]="existingPlusCurrent" ...>
Controller
existing: [] // some list of values to be used
existingPlusCurrent: [] // array that is used by the autoComplete
inputChanged(event: KeyboardEvent): void {
const value = event.srcElement.value;
if (this.existing.indexOf(value) === -1) {
this.existingPlusCurrentLabel = [value, ...this.existingLabels];
} else {
this.existingPlusCurrentLabel = this.existingLabels;
}
}
This way one can select the value as expected from the dropdown.
I just ported this @doeringp Angular solution over to Vue 3 if anyone needs it:
import Autocomplete from 'primevue/autocomplete';
const handleAddNewEmail = (event) => {
const newVal = [
...props.sentTo,
event.srcElement.value,
];
v$.value.sent_to.$model = newVal;
emit('update:sent-to', newVal);
event.srcElement.value = '';
};
...
<Autocomplete
v-model="v$.sent_to.$model"
:suggestions="[
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
]"
multiple
@keydown.enter="handleAddNewEmail"
/>
The important thing is to hook into the keydown event with .enter event modifier. This will fire your function with the first parameter being the keyboard event.
Next, the critically important thing and really all you need is event.srcElement.value. You can push that value into your v-model value (which is an array), and then you can wipe the value by setting event.srcElement.value to "".
Zombie thread, I know, but in case anyone stumbles upon this and requires an easy solution - what you can do is prepend the query in the completeMethod handler. No need to fiddle with the keyUp event.
Modyfing the example from the docs it would look something like this:
filterCountry(event) {
//in a real application, make a request to a remote url with the query and return filtered results, for demo we filter at client side
let query = event.query;
// also suggest the query itself
let filtered: any[] = [query];
for (let i = 0; i < this.countries.length; i++) {
let country = this.countries[i];
if (country.name.toLowerCase().indexOf(query.toLowerCase()) == 0) {
filtered.push(country);
}
}
this.filteredCountries = filtered;
}