Custom Component Within form Field

2 Answers 274 Views
Form MultiColumnComboBox
Henintsoa
Top achievements
Rank 1
Iron
Henintsoa asked on 10 May 2023, 11:15 AM
Hello,
I use Kendo UI Angular,
I have a kendomulticombobox in a form, I use this combobox in several forms, and to avoid copying and pasting, I thought of setting up a separate component for that, and just call it each time I need.
It's to say that the form has a formgroup, and that this formgroup has several formcontrols, that I get when I submit the form.
So when I integrate my custom component, I get an error `ERROR Error: No value accessor for form control with name:` and yet it's the same formcontrol that I use before.

Has anyone experienced this kind of problem? Or do you have any solutions please? Thanks

2 Answers, 1 is accepted

Sort by
1
Accepted
Martin
Telerik team
answered on 15 May 2023, 09:19 AM

Hi Henintsoa,

If I understand correctly a custom wrapper component is created for the MultiColumnComboBox and it needs to be used in a Reactive form. Please correct me if I am wrong.

Creating form control wrapper is more related to how the Angular form is configured rather than to the Kendo UI for Angular built-in API.

A possible approach to wrap an Angular Reactive Form control in a separate component is to set the viewProviders as suggested in the following Stack Overflow comment:

https://stackoverflow.com/a/53693760/10469244

import { ControlContainer, FormGroupDirective } from '@angular/forms';
 
selector: 'my-dropdown',
  viewProviders: [
    { provide: ControlContainer, useExisting: FormGroupDirective },
  ],
  template: ` `,
})

Here is an example where the <form-field> component is defined in a custom component:

 <form  [formGroup]="form">
          <my-dropdown ...></my-dropdown>
</form>

https://stackblitz.com/edit/angular-ppgg1c-k1xgzu

Please check the provided example. In case this doesn't answer the question, could I ask you for some more details about the requirement and what is the currently used markup. Thank you in advance.

Regards,
Martin
Progress Telerik

Stay tuned by visiting our public roadmap and feedback portal pages! Or perhaps, if you are new to our Kendo family, check out our getting started resources
0
Henintsoa
Top achievements
Rank 1
Iron
answered on 15 May 2023, 09:37 AM | edited on 15 May 2023, 09:40 AM
Hello Martin,
Thank you for your answer.

Yes, the answer i have searching for is in the stackblitz link.
The solution is to declare the formcontrol as string first.
Thanks for helping and wishing you good day.

Regards,
Henintsoa
Tags
Form MultiColumnComboBox
Asked by
Henintsoa
Top achievements
Rank 1
Iron
Answers by
Martin
Telerik team
Henintsoa
Top achievements
Rank 1
Iron
Share this question
or