Combobox default value in formControl is object

Hi! I have a combo box with a form control of angular forms and I set the initial value to be and object, the data source is an array of those objects.

https://stackblitz.com/edit/angular-1wwuu2-f5vj6q?file=app.component.html

Here is the example:
How can I set correctly the initial value of the combo box in the FormControl, I want that value to be the object in the array, so when its changes it updates that value object.

Thanks

5 Replies

PM Ponmani Murugaiyan Syncfusion Team October 1, 2020 05:03 PM UTC

Hi Cesar, 

Greetings from Syncfusion support. 

As per your requirement we have prepared sample to achieve “initial value of the combo box in the Form”. Please find the modified sample below for reference. 

export class AppComponent { 
  ds = [ 
    { name: 'name1', text: 'NAME 1' }, 
    { name: 'name2', text: 'NAME 2' } 
    ] 
 
   public form: FormGroup; 
     
    ngOnInit() { 
    // create a form with pre-populated control 
    const fb = new FormBuilder(); 
    this.form = fb.group({ 
      control: 'name2' 
    }); 
  } 
} 


 

 
Kindly check the above sample meets your requirement. Please get back us if you need further assistance. 

Regards, 
Ponmani M 



CS Cesar Smerling October 1, 2020 08:32 PM UTC

Hello!

Yes, that works but I want to init the control the whole object not one property. And when the valueChanges the value that I receive is the object, because I need to do some operations with the object and I have to find in the dataSource.

I thought that in the fields the "text" value is what is shown and the "name" is like the id of the object in the dataSource


BC Berly Christopher Syncfusion Team October 2, 2020 11:39 AM UTC

Hi Cesar, 
  
From the provided details we suspect that you want to set the value property as object to the combo box component. We would like to inform you that, we can set the value property for the combbox component as number and string.  
  
If we misunderstood your query, please share the exact requirement that will help us to check and proceed further from our end. 
  
Regards, 
Berly B.C 



CS Cesar Smerling October 2, 2020 12:08 PM UTC

Hello!

Yes that's what I ment.


PM Ponmani Murugaiyan Syncfusion Team October 6, 2020 12:27 PM UTC

Hi Cesar, 

Thanks for the update. 

Currently the value property accepts only String, Number or Boolean value. The reported requirement “Bind the dropdownlist value property as object”  has been considered as a feature in our end. At the planning stage for every release cycle, we review all open features and this will be included in any of our upcoming future releases.  

You can now track the current status of your request, review the proposed resolution timeline, and contact us for any further inquiries through below link:  


Regards, 
Ponmani M 


Loader.
Up arrow icon