samedi 25 avril 2020

Get values from a Reactive Form check box

Good, I am implementing a Reactive Form, but I have a problem getting the values from the checkbox, only the value of the first of the value I select appears and not the others. I attach my code:

Component.ts

registerForm: FormGroup;

  builder(
     private Restservice: RestserviceService,
     private route: ActivatedRoute,
     private router: Router,
     private formBuilder: FormBuilder
   ) {

     this.registerForm = this.formBuilder.group ({
       text: [""],
       checkArray: [""],
       radiobutton: [""],
       array: [""],
       list: [""],
       archive: [""],
       date: [""],
       numeric: [""],
       CommonData: [""],
     });
   }

// I show the values of the Form
  submit () {
     if (this.registerForm.valid) {
       console.log ("complete", this.registerForm.value);
       // this.createAnswers ();
     } else {
       alert ("FILL ALL FIELDS");
     }
   }

I use primeng's p-checkbox here but the problem is that it only recognizes the first value selected and the others don't.

 Html.

<div *ngIf="p.codigo_tipopreguntas == 2">
                            <ng-container *ngFor="let v of valores; let i=index">
                              <div *ngIf="p.id === v.codigo_pregunta">
                                  <p-checkbox  value=""
                                    label="" formControlName="checkbox"></p-checkbox>
                              </div>
                            </ng-container>
                          </div>

 <button class="btn btn-info btn-just-icon btn-round btn-link" pTooltip="Guardar" tooltipPosition="top"
              (click)="submit()">
              <i class="material-icons">remove_red_eye</i>
            </button>

attached picture of what the submit function prints




Aucun commentaire:

Enregistrer un commentaire