3

I have these html button:

<form ngNativeValidate (ngSubmit)="onSubmit()" #add_form="ngForm">
     <button class="btn btn-primary " type="submit[disabled]="!add_form.valid">ADD</button>
     <button class="btn btn-default" (click)="back()">Back</button>
</form>

And I obtain this warning in the console:

Form submission canceled because the form is not connected

Anyone can help me to resolve this warning?

Rarblack
  • 4,559
  • 4
  • 22
  • 33
Doflamingo19
  • 1,591
  • 4
  • 12
  • 32

1 Answers1

13

For your Back button, add type="button" to the declaration, like this:

<form ngNativeValidate (ngSubmit)="onSubmit()" #add_form="ngForm">
     <button class="btn btn-primary " type="submit[disabled]="!add_form.valid">ADD</button>
     <button type="button" class="btn btn-default" (click)="back()">Back</button>
</form>

What's happening, is that Angular interprets the second button as another submit button, and so you're effectively navigating in the middle of a submit. That's why the messages tells you that form submission is being cancelled.

Cobus Kruger
  • 8,338
  • 3
  • 61
  • 106