Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

297
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda