We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Dropdownlist reactive form setValue not working

Thread ID:

Created:

Updated:

Platform:

Replies:

148526 Oct 23,2019 02:59 PM UTC Oct 29,2019 09:00 AM UTC Angular - EJ 2 3
loading
Tags: DropDownList
Jose Luis Garcia
Asked On October 23, 2019 02:59 PM UTC

Hello,

I'm having a problem assigning a value to a reactive form control dropdownlist. Value is not set.

Form definition:

  private defineForm() {
    this.form = this.fb.group({
      userName: new FormControl(this.authService.getUser().userName, [Validators.required, Validators.maxLength(50)]),
      startDate: new FormControl(new Date(), [Validators.required]),
      endDate: new FormControl('', [Validators.required]),
      reason: new FormControl('', [Validators.required]),
      approved: new FormControl(false, [Validators.required])
    });
  }

  get userName() { return this.form.get('userName'); }
  get startDate() { return this.form.get('startDate'); }
  get endDate() { return this.form.get('endDate'); }
  get reason() { return this.form.get('reason'); }
  get approved() { return this.form.get('approved'); }


This part works fine. Default value is assigned.

The next part is not working:

this.userName.setValue(this.absence.userName);

No value is assigned. If I look for this.userName, I see property 'value' with old value.

Any idea?
Regards
Jose


Narayanasamy Panneer Selvam [Syncfusion]
Replied On October 24, 2019 05:01 PM UTC

Hi Jose, 
Greetings from Syncfusion Support. 
We have validated your requirement. Yes, we can update dropDownlist value through reactive form setValue method.  
 
Code example: 
App.component.html 
<ejs-dropdownlist formControlName="skillname" name="skillname" [dataSource]='autoreactiveskillset' 
    [placeholder]='autoreactiveplaceholder'> 
</ejs-dropdownlist> 
 
<button style="float:right" type="button" (click)="setDefaultValue()">Set Value</button> 
 
 
app.component.ts 
 public autoreactiveskillset: string[] = [ 
  'ASP.NET''ActionScript''Basic', 
  'C++''C#''dBase''Delphi', 
  'ESPOL''F#''FoxPro''Java', 
  'J#''Lisp''Logo''PHP' 
]; 
 
setDefaultValue() { 
  this.userForm.setValue({ name: 'John', skillname: 'Delphi', age: 20 }); 
} 
 
We have prepared a sample to update dropdown list value using button click. Please get it from below link, 
Also, we would like to inform you that the DropDown List will accept only accept already present in referred data source. 
 
Kindly let us know if you need further assistance on this.

Regards,
Narayanasamy P.
 


Jose Luis Garcia
Replied On October 28, 2019 12:05 PM UTC

Hi Narayanasamy,

Thank you very much for your support.

I've tested agains your code and now is working fine.

Regards

Jose



Sureshkumar P [Syncfusion]
Replied On October 29, 2019 09:00 AM UTC

Hi Jose, 
 
Most welcome. Please let us know if you require any further assistance. 
 
Regards, 
Sureshkumar P 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon