I'm having an issue trying to work with multiple checkboxes i bring from the backend:
First i need that the data selected by the user from checkboxes sends to the back, but only i have object: "0:" in the payload console. I am using Angular v13 as a front-end with Reactive Forms. So i will ask for a hand.
This is the code:
TS
conocimientosInformatica: string[] | undefined;
//This function brings the data from API
getDatos() {
this.alta_service.getInscripcion()
.subscribe((data: any) => {
const conocimientosInformatica = data.formacion.estudios.conocimientos_de_informatica;
this.conocimientosInformatica = Object.keys(conocimientosInformatica["#options"]);
console.log(this.conocimientosInformatica);
});
}
//I got the data from conocimientos_de_informatica field in the backend
get conocimientos_de_informatica() { return this.educationAndSkills.get('conocimientos_de_informatica') as FormArray };
//And Created myFormBuilder
educationAndSkills = this.formBuilder.group({
conocimientos_de_informatica: this.formBuilder.array([''])
})
This is the output:
(4) ['Procesadores de texto', 'Planillas de cálculo', 'Software de gestión', 'Otros']
In my HTML View i put it like this:
<div class="fieldset-wrapper">
<div class="js-webform-checkboxes webform-options-display-one-column form-checkboxes" *ngFor="let informatica of conocimientosInformatica; index as i" formArrayName="conocimientos_de_informatica">
<div class="js-form-item form-item js-form-type-checkbox form-type-checkbox js-form-item-conocimientos-de-informatica">
<input type="checkbox" name="conocimientos_de_informatica" [formControlName]="i" value="{{informatica}}" class="form-checkbox">
<label for="edit-conocimientos-de-informatica-checkboxes" class="option">{{informatica}}</label>
</div>
</div>
</div>
Tried other several ways posted here, but don't apply in my case because here the Array of checkboxes are brought via the API. I need to send the data checked to the Backend results.
I would appreciate your help.