Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

251
Views
How do we give input type as Reset and a Click event on Reset

I have a Reset button with input type = reset. On click of the Reset button, I need all fields to clear first and then I have to execute a method. So I am using a click event but not able to execute both with type reset.

<button type="reset">Reset</button>                          // Line 1
<button (click)="resetView()" type="button">Reset</button>  // Line 2
resetView(){
  // Some method
}

The first line is enabling only reset of fields. The second line is only hitting the resetView() method without clearing out the fields. How do I include both the reset and resetView() method

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

There are 3 ways comes to my mind that form can be handled in angular:

  1. using form tag:
<form #myForm>
 <!-- here some other controls -->
 <button (click)="myForm.reset(); resetView()">Reset</button>
</form>
  1. using ngModel:
 <input [(ngModel)]="myInput1"/>
 <input [(ngModel)]="myInput2"/>
 <!-- here some other controls -->
 <button (click)="resetForm(); resetView()">Reset</button>
resetForm(){
  this.myInput1 = '';
  this.myInput2 = '';
  // etc.
}
resetView(){
  // Some method
}
  1. using FormGroup:
<div [formGroup]="myForm">
 <input formGroupName="myInput1"/>
 <input formGroupName="myInput2"/>
 <!-- here some other controls -->
 <button (click)="resetForm(); resetView()">Reset</button>
</div>
readonly myForm = new FormGroup({
  myInput1: new FormControl(''),
  myInput2: new FormControl(''),
  // etc.
});

resetForm(){
  this.myForm.reset();
}
resetView(){
  // Some method
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!