Topic: Validate form on button click

jimsgroup pro asked 6 years ago


Rather than adding mdInputValidate to an input field to validate after leaving the field, how can I validate all fields when the user click a submit button?

Dawid Adach pro answered 6 years ago


Dea jimsgroup,
You can use "dirty" for that and built in ngForm validation using i.e. myForm.valid as below:

<form #myForm="ngForm" (ngSubmit)="register(myForm)" novalidate>

<p>Is "myForm" valid? {{myForm.valid}}</p>
<div class="md-form">

<i class="fa fa-user prefix grey-text"></i>

<input type="text"id="form3" class="form-control"mdbActive ngModel required name="name">

<labelfor="form3">Your name</label>

</div>
<div class="text-center">

<button class="btn btn-unique waves-light"mdbRippleRadius>Send <i class="fa fa-paper-plane-o ml-1"></i></button>

</div>

</form>

You can find more detailed validation technics in following article:
https://www.toptal.com/angular-js/angular-4-forms-validation



Please insert min. 20 characters.

FREE CONSULTATION

Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.

Status

Answered

Specification of the issue

  • ForumUser: Pro
  • Premium support: No
  • Technology: MDB Angular
  • MDB Version: -
  • Device: -
  • Browser: -
  • OS: -
  • Provided sample code: No
  • Provided link: No
Tags