0

I'm trying to submit a product and i need to get also the this.totals[].amount and this.totals[].total. Right now, i can only get the this.myForm.get('rows').value. I need to insert in the rows the this.totals[].amount and this.totals[].total. How can i do this? Here's the link to my code

CLICK LINK HERE

onCreateProduct(){
   const formData = {
     products: this.myForm.get('rows').value
   }
   console.log(formData)

  }

patchValues() {
    let rows = this.myForm.get('rows') as FormArray;
    this.orders.forEach(material => {
      material.materials.forEach(x => {
        rows.push(this.fb.group({
          material_id: x.id,
          material_name: x.name,
          quantity: [null, Validators.required],
          price: [null, Validators.required],
          dis_checkbox: [true],
          checkbox: [1.12]
        })) //see that total and amount is NOT in the form
        this.totals.push({amount:0,total:0});  //<--add this line
      })
    })
    this.setOnChange();
  }

1 Answer 1

2

You can easily add data to your rows on submit in your onCreateProduct function. Change the code to the following:

const formData = {
  products: this.myForm.get('rows').value.map((row, i) => {
    row.amount = this.totals[i].amount;
    row.total = this.totals[i].total;
    return row;
  })
}
Sign up to request clarification or add additional context in comments.

1 Comment

The other values for each product are still there. We're just adding the this.totals information onto the existing product information. You could replace the variable row with the variable product if that would make more sense.

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.