Hi, this is my DropDownList component inside a reactive form:
and this is how I'm loading and updating controls:
but the control is not displaying selected option when customer is loaded (this.customer.idRegistrationRate is the property coming from customer):
If I select an option, it's working fine:
Any ideas about my problem?
Regards
Jose
|
constructor(private fb: FormBuilder) {
this.createForm();
}
createForm(): void {
this.skillForm = this.fb.group({
action: ['2', Validators.required],
});
} |
Hi Ponmani,
Thanks a lot for your quick response.
If you check the ngOnInit method, the value is set after loading from the server the list of registration rates.
After loading the list, I update the form controls with their values (form patch method).
If I inspect the control in runtime, I can see that the value has been assigned correctly, but the text is not displayed.
Regards
Jose
|
public actionFields: Object = { text: 'Game', value: 'id' };
public actionData: { [key: string]: Object }[] = [
{ id: '1', Game: 'Proceed' },
{ id: '2', Game: 'Triage' },
{ id: '3', Game: 'Forward' },
{ id: '4', Game: 'Bounce' },
];
createForm(): void {
this.skillForm = this.fb.group({
action: ['2', Validators.required],
});
} |
Hi Ponmani,
I'm updating the id of the object, as you can see in previous screenshot (value: 4), but to be sure, after getting datasource elements from server, I've tried to set the value with (its a reactive form):
but with the same result, no text is set in the control.
I'm sure it's my mistake, but I can't figure out where the error lies.
Regards
Jose
|
onCreate() {
this.skillForm.controls.skillname.setValue(4);
} |
Hi Ponmani,
That is precisely what I am doing with "this.f.idRegistrationRate.setValue(4);" (this.f is just a shortcut of "this.form.controls").
To get out of doubt I have created a simple test with a button that when you press it assigns a value to the control with this code:
This simple test fails. When I press the button, value is assigned to dropdownlist (I can see that inspecting the control) but no text is displayed.
Do I have to refresh the control after assigning the value?
Regards
Jose
Hi Ponmani,
I've found my mistake...
I was trying to assign the id as string and it's a number. That's the problem.
I'm sorry to have bothered you with my mistake.
Regards
Jose