Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

296
Views
How to reset the formArray values to default values ?since form.reset() makes it null

I am new to angular and I have a form with these fields.

 this.catform = new FormGroup({
  name: new FormControl('', Validators.required,),
  source: new FormControl('', Validators.required),
  event: new FormControl('', Validators.required),
  cond:  this.fb.array([this.Cond()], Validators.required)     
});

 Cond() : FormGroup {
return this.fb.group({
  disp : new FormControl(1),
  field: new FormControl('', Validators.required),
  ct: new FormControl('', Validators.required),
  value: new FormControl('', Validators.required),
  ot : 'AND'
});
}

After submitting the form, I do the this.catform.reset(), but this resets the "disp" and "ot" to null, and thus makes my form have the values to null. Now when I submit this form again, it is unsuccessful in the backend since those values are null in the form but the backend doesnt accept this creation.So I want these to be as the ones which I have mentioned above, and I don't have these 2 fields in the HTML template, so I cannot edit them from the HTML template. Please if anyone could suggest some way.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Convert the following code into a method. And when you want to reset, just call the method and assign it to this.catform

new FormGroup({
    name: new FormControl('', Validators.required,),
    source: new FormControl('', Validators.required),
    event: new FormControl('', Validators.required),
    cond:  this.fb.array([this.Cond()], Validators.required)
});

Like this:

this.catform=this.getFormgroup();

private getFormgroup() {
    return new FormGroup({
    name: new FormControl('', Validators.required,),
    source: new FormControl('', Validators.required),
    event: new FormControl('', Validators.required),
    cond:  this.fb.array([this.Cond()], Validators.required)
    });
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!