New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(forms): add NgForm method that resets submit state #10715

Merged
merged 1 commit into from Aug 12, 2016

Conversation

Projects
None yet
4 participants
@kara
Contributor

kara commented Aug 12, 2016

This PR adds a resetForm method to top level form directives: NgForm and FormGroupDirective. These directives have a concept of submission (through the submitted property) that does not exist for form control models, so it cannot just fall through to the existing resetting mechanism on AbstractControls. So when you'd like to reset the form from the top level and set submitted to false, use resetForm() instead.

This PR also ensures that native reset buttons will reset submitted to false as well.

Before

@Component({
   selector: 'my-comp',
   template: `
     <form>
        <input name="first" ngModel>
     </form>
  `
})
class MyComp {
  @ViewChild(NgForm) form: NgForm;

  reset() {
    this.form.reset();    // calls FormGroup reset(), submitted == true;
  }

}

After

@Component({
   selector: 'my-comp',
   template: `
     <form>
        <input name="first" ngModel>
     </form>
  `
})
class MyComp {
  @ViewChild(NgForm) form: NgForm;

  reset() {
    this.form.resetForm();       // calls FormGroup reset(), submitted == false
  }
}

Note: this is not a breaking change, as the original reset() method of NgForm still exists and works the same way.

@googlebot googlebot added the cla: yes label Aug 12, 2016

@kara kara assigned kara and unassigned vsavkin Aug 12, 2016

@kara kara assigned vsavkin and unassigned kara Aug 12, 2016

@vikerman vikerman merged commit 97f3571 into angular:master Aug 12, 2016

3 checks passed

ci/circleci Your tests passed on CircleCI!
Details
cla/google All necessary CLAs are signed
continuous-integration/travis-ci/pr The Travis CI build passed
Details

@kara kara added the comp: forms label Sep 5, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment