0

I have a form which onSubmit should reset the value of specific form field. So far I have tried the following:

Ts file:

ngOnInit() {
    this.loading = true;
    this.getIncident();
    this.loading = true;
      })
      this.addCommentsForm = new FormGroup({
        comment: new FormControl(''),
        number: new FormControl('')
      })
    }

onSubmit() {

      let putData = Object.assign({}, this.addCommentsForm.value);
      console.log('form, ', putData)
      this.uploading = true;
      this.commentProgress.progress = 100;
      this.service.putIncidentsComments(putData, this.s_id).subscribe((response: any) => {
        console.log("comment sent");
        this.getIncidentComments();
        this.uploading = false;
        this.commentProgress.progress = 0;
        this.addCommentsForm.reset();
      }, (errorResponse: any) => {
        console.log(errorResponse); //On unsuccessful response
        this.error = true;
        this.uploading = false;
      });
    }
  }

the line: this.addCommentsForm.reset(); resets the whole form and I just want the comment field reset? any ideas?

1 Answer 1

1

You can get the formControl and reset it:

this.addCommentsForm.get('comments').reset();
Sign up to request clarification or add additional context in comments.

Comments

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.