OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

reactive form 'patchValue not updating the form control p-dropdown

  • Thread starter Thread starter s d
  • Start date Start date
S

s d

Guest
I have left panel that has form control fields, based on p-dropdown selection , I am updating the right panel content. On page load I am trying to show default values on dropdowns but due to form arrays not updating, the I am not able to see the default values on p-dropdown. Can some please help?

Code:
  ngOnInit(): void {
    this.formcopy = this.fb.group({
      scenariotype: [null],
      case: [ null]
    });
    this.getCaseNames();
    this.loadScenarioData(this.scenarioId);
   
  }
  getCaseNames(){
    this.globalparaService.getParam('27e1423a-0d12-1213-b113-aace6639ae08').subscribe((res) => {
      res.data.Case.map(obj => {
        this.caseName.push({ name: obj.CaseName, code: obj.CaseName });
      });
     
    });
  }

  loadScenarioData(scenarioId) {
    this.service.getScenarioByScenarioId(scenarioId).subscribe((res) => {
      this.populateFormdata(res.data);
    });
  }

    populateFormdata(data){
      this.formcopy.patchValue({
      scenariotype: ['Low'],// not updating even though using hardcoded value
      case: [ 'P50']// same here , FE not updating these values
    });



<form [formGroup]="formcopy">
   <p-dropdown [options]="scenario" (onChange)="setScenarioType($event)" optionLabel="name" optionValue="code"
              formControlName="scenariotype" ngDefaultControl ></p-dropdown>

    <p-dropdown [options]="caseName" (onChange)="setCaseName($event)" optionLabel="name" optionValue="code"
            formControlName="case" ngDefaultControl></p-dropdown>
</form>

<p>I have left panel that has form control fields, based on p-dropdown selection , I am updating the right panel content. On page load I am trying to show default values on dropdowns but due to form arrays not updating, the I am not able to see the default values on p-dropdown. Can some please help?</p>
<pre><code> ngOnInit(): void {
this.formcopy = this.fb.group({
scenariotype: [null],
case: [ null]
});
this.getCaseNames();
this.loadScenarioData(this.scenarioId);

}
getCaseNames(){
this.globalparaService.getParam('27e1423a-0d12-1213-b113-aace6639ae08').subscribe((res) => {
res.data.Case.map(obj => {
this.caseName.push({ name: obj.CaseName, code: obj.CaseName });
});

});
}

loadScenarioData(scenarioId) {
this.service.getScenarioByScenarioId(scenarioId).subscribe((res) => {
this.populateFormdata(res.data);
});
}

populateFormdata(data){
this.formcopy.patchValue({
scenariotype: ['Low'],// not updating even though using hardcoded value
case: [ 'P50']// same here , FE not updating these values
});



<form [formGroup]="formcopy">
<p-dropdown [options]="scenario" (onChange)="setScenarioType($event)" optionLabel="name" optionValue="code"
formControlName="scenariotype" ngDefaultControl ></p-dropdown>

<p-dropdown [options]="caseName" (onChange)="setCaseName($event)" optionLabel="name" optionValue="code"
formControlName="case" ngDefaultControl></p-dropdown>
</form>
</code></pre>
 

Latest posts

D
Replies
0
Views
1
Damiano Miazzi
D
Top