4

I have a simple form with different types of fields. On submitting the form, I just print the values submitted.

It looks fine for a few fields, however it doesn't work as expected for multiselect and checkbox fields.

For multiselect and checkboxes only latest selected values is printed. Instead, I want an array.

Any suggestions on how to do this?

Also for the file attachment field, how can I add the filelist to the original object (Created using FormBuilder & ControlGroup) with rest of the field values?

this.SampleForm = formBuilder.group({
        title: ['', Validators.required],
        description: ['', Validators.required],
        countries: ['', Validators.required],
        attachment: ['', Validators.required],
        continents: ['', Validators.required]
    });

Plunker Link

Form

Output after submit

Pardeep Jain
  • 84,110
  • 37
  • 165
  • 215
Saravanan
  • 1,237
  • 2
  • 18
  • 25

2 Answers2

0
<input type="checkbox" id="SelectAll" name="SelectAll" value="SelectAll" (click)="toggleSelect($event)"  />
<input type="checkbox" name="data[{{i}}]" [checked]="data.selected" value="data.selected" id="{{data.name}}" (change)="data.selected =!(data.selected)" /> 
 toggleSelect = function(event){     
        this.SelectAll = event.target.checked;
        this.data.forEach(function(item){

         console.log(item);

         item.selected = event.target.checked;
      });

}    
lohita
  • 31
  • 3
0

if you want to get array of selected values, you can make your continents form control as an formarray. and put formControlName and select list. so that values selected can be passed as an array.