0

I have a reactive form with a submit button and a reset button. Both are working as expected, but the reset function shows the Toast message that is triggered from the submit.

onSubmit() { 
        this.service.update(data, this.id)
            .subscribe(response => {
                this.getDetails();
                this.toaster.showToaster('Saved.');
            }); 
    }

resetForm(){
        this.setFormValues();
    }

setFormValues() {
        this.form.setValue({
            name: this.plan.name,
            account: this.plan.account
        });
    }

getDetails() {
        this.service.getById(this.id)
            .subscribe(rem => {
                this.plan = rem;
                this.setFormValues(); 

            });
    }

HTML:

<form [formGroup]="form" (ngSubmit)="onSubmit();" novalidate>

<table class="detailTable">
    <tr>
        <td>name:</td>
        <td>{{name}}</td>
    </tr> ...
</table>

    <div class="button-row">
        <button type="submit" [disabled]="form.pristine" md-raised-button>Save</button>
        <button (click)="resetForm()" [disabled]="form.pristine" md-raised-button>Reset</button>
    </div>

<span>

 </span>
</form>

When I click on Reset, the form is reset, and it shows "Saved." message. What am I doing wrong?

Achraf JEDAY
  • 1,936
  • 5
  • 24
  • 33
Jay
  • 329
  • 1
  • 6
  • 22

1 Answers1

0

this worked: $event.preventDefault()

Thanks for that link, Achraf JEDAY!

Jay
  • 329
  • 1
  • 6
  • 22