0

Hi i am using Angular8 with Bootstrap, here i have used reactive forms, when i check on Make Default checkbox, then values present in Flowers row (Mail, Electronic,Delivery and Receipent)should be copied same to rest rows.

If the fax number format is not proper, how to show error message just below particular row recepient.

Ts:

 checkAll(ev) {
    const control = <FormArray>this.exampleForm.get("printList");
    if (!this.all) {
      this.printListArray.forEach(x => (x.value = false));
      control.patchValue(this.printListArray);
    } else {
      this.printListArray.forEach(x => (x.value = true));
      control.patchValue(this.printListArray);
    }
    console.log(control.value);
  }

  isAllChecked() {
    this.all = !this.all;
  }

DEMO

1 Answer 1

1

Your code should work more like the following

  checkAll(ev) {
    const control = <FormArray>this.exampleForm.get("printList");
    console.log(this.all);
    if (this.all) {
      this.all = false;
      this.printListArray.forEach(x => (x.electronics = false));
      control.patchValue(this.printListArray);
    } else {
      this.all = true;
      this.printListArray.forEach(x => (x.electronics = true));
      control.patchValue(this.printListArray);
    }
  }

The main difference is that instead of changing the value field of x I'm changing the electronics fields, so when you are patching the form latter on, this.printListArray will have the appropriate data in the appropriate state.

In the implementation that I'm suggesting you will be able to toggle all checboxes in the row Electronics

Keep in mind that the printListArray is not an array form FormGroup/FormControl, its an array of regular objects, so the field value that usually exists in the FormControl is not present.

Sign up to request clarification or add additional context in comments.

12 Comments

Thanks for response, but sorry i am not able to run output
What do you mean by run output?
I tried this link, but my requirement is different, in the first row, (Flowers row), we have mail, electronics, Delivery dropdown, Recepient, when Make Default is checked, what mail value, electronic value, delivery dropdown value, recepient value is present for Flowers row, should be copied to all rows, something like If selected, copy the field values (check boxes, drop down, and text box) to all other rows.
Check the link again, i've made it so that whenever you click the "Make the same as firt rows" button the value from the first row will be applied across the rest of the rows, the logic is the same as with the checkboxes, the only difference is that here im updating the form itself instead the array of elements
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.