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

397
Views
HTML5 required attribute not working in Angular 2 project, installed using CLI

I am working on Angular 2 login page, when I try to validate input field with HTML 5 validate attribute required, it is not working, where as in the quick start project it works fine. Could any one explain why it is not working and how to resolve this issue ?

Plunker link of my code In Plunker, it validates but in my project its not working.

app.component.html code below,

<form class="login-form">
  <input type="text" name="usrname" placeholder="Username"  required/>

  <input type="password" name="pwd" placeholder="Password"  required>
  <input type="submit">

</form>
about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

As of version 4.0.0, Angular automatically adds "novalidate" to the form. Change this new default behavior by using:

<form ngNativeValidate>...</form>

Github issue here: https://github.com/angular/angular/issues/15531#issuecomment-289555359

about 4 years ago · Santiago Trujillo Report

0

     <form class="login-form" novalidate> 
    <input type="text" name="usrname" placeholder="Username" required="required"> 
<input type="password" name="pwd" placeholder="Password" required="required"> 
<button type="submit">Submit </button> 
    </form> 

remove novalidate from your form tag to enable html5 validation

<form class="login-form" >

If you use novalidate in your form tag, the validation wont occur as that's that the novalidate keyword is for when you don't want the default html5 validation and you want to implement your own validation means you have to use the novalidate otherwise you don't need it

about 4 years ago · Santiago Trujillo 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!