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

120
Views
Angular 4 habilita la validación de HTML5

Quiero usar la validación de HTML5 en Angular 4 en lugar de la validación/validación reactiva basada en su formulario. Quiero mantener la validación ejecutándose en el navegador.

Solía funcionar en Angular 2, pero desde que actualicé, ni siquiera puedo obtener formularios creados manualmente sin directivas angulares para validar usando HTML5.

Por ejemplo, esto no validará en absoluto en el navegador:

 <form> <h2>Phone Number Validation</h2> <label for="phonenum">Phone Number (format: xxxx-xxx-xxxx):</label><br /> <input id="phonenum" type="tel" pattern="^\d{4}-\d{3}-\d{4}$" required> <input type="submit" value="Submit"> </form>
about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Angular4 agrega automáticamente un atributo novalidate a los formularios.

ingrese la descripción de la imagen aquí

Para anular esto, puede agregar la directiva ngNativeValidate al formulario.

 <form ngNativeValidate> <h2>Phone Number Validation</h2> <label for="phonenum">Phone Number (format: xxxx-xxx-xxxx):</label><br /> <input id="phonenum" type="tel" pattern="^\d{4}-\d{3}-\d{4}$" required> <input type="submit" value="Submit"> </form>

Desafortunadamente, todavía no veo esto reflejado en los documentos, pero lo encontré mirando el código fuente: https://github.com/angular/angular/blob/master/packages/forms/src/directives/ng_no_validate_directive.ts

Parece que agregar ngNoForm al formulario tiene el mismo efecto que ngNativeValidate dependiendo de sus casos de uso por la necesidad de declarar algo que no es un formulario por cualquier motivo.

Espero que esto ayude.

about 4 years ago · Santiago Trujillo Report

0

use ngNoForm o ngNativeValidate en su formulario

 <form ngNoForm/ngNativeValidate> ... </form>
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!