This is a migrated thread and some comments may be shown as answers.
ValueNormalizer Returns - Add to List?
2 Answers 5 Views
This is a migrated thread and some comments may be shown as answers.
Keith
Top achievements
Rank 1
Keith asked on 04 Mar 2021, 08:30 PM

Good day!  Here is another question on the ComboBox allowing custom additions.

When the valueNormalizer function returns, is  there a simple way to have the new accepted value be automatically added to the the data list without requesting essentially a refresh?

2 Answers, 1 is accepted

Sort by
0
Keith
Top achievements
Rank 1
answered on 05 Mar 2021, 06:04 PM
I believe I have a good solution in place.  I'll provide a code sample soon.
0
Martin
Telerik team
answered on 08 Mar 2021, 11:03 AM

Hello Keith,

In order to be added to the ComboBox list, custom values need to be pushed to the bound array collection. To ensure that the reference of the array is changed (in order to trigger the Angular change detection), the most straightforward approach is to utilize spread operator:

public valueNormalizer = (text: Observable<string>) =>
    text.pipe(
      map((content: string) => {
        const newValue = {
          value: this.listItems[this.listItems.length - 1].value + 1,
          text: content
        };
        this.listItems = [...this.listItems, newValue];
        return newValue;
      })
    );

Here is an example where the custom values are automatically added to the list:

https://stackblitz.com/edit/angular-n7aseu

Please write back in case any further assistance is required for this case.

Regards,
Martin
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Asked by
Keith
Top achievements
Rank 1
Answers by
Keith
Top achievements
Rank 1
Martin
Telerik team
Share this question
or