Skip to content

<input> required attribute not respected (4.0.0 regression) #15531

Closed

Description

@buu700

I'm submitting a ...

[x] bug report
[ ] feature request
[ ] support request

Current behavior

Submitting a form with an empty <input required /> succeeds.

Expected behavior

As with 2.x, the submit event should be blocked and the browser should display an error message message like this one:
screen shot 2017-03-27 at 3 06 57 pm

Minimal reproduction of the problem with instructions

Click the submit button in a form like this:

<form (submit)='doSomething()'>
	<input type='text' name='text' required />
	<input type='submit' />
</form>

What is the motivation / use case for changing the behavior?

Functionality regression.

Please tell us about your environment:

  • Angular version: 4.0.0

  • Browser: Chrome 57

  • Language: TypeScript 2.2.1

  • Node (for AoT issues): 6.10.1

  • Operating System: Debian Jessie (in a Docker container on OS X El Capitan)

Activity

  1. DzmitryShylovich commented on Mar 27, 2017

    @DzmitryShylovich
    Contributor

    Angular automatically has added novalidate attribute since 4.0 . To disable it add ngNativeValidate:

    <form ngNativeValidate>...</form>
    
  2. buu700 commented on Mar 27, 2017

    @buu700
    Author

    Ah, that was the problem. Thanks!

    Looking back at the changelog, I see that this change was discussed in some of the RC feature bullets, but never listed as a breaking change; might be worth adding it to the breaking changes for others who may run into this in the future.

  3. DzmitryShylovich commented on Mar 27, 2017

    @DzmitryShylovich
    Contributor

    @StephenFluin can you please update the changelog and your migration app with this change?

  4. rwngallego commented on Jul 24, 2017

    @rwngallego

    This should be also mentioned in the official docs. I don't see any reference to this breaking change.

  5. kemsky commented on Mar 9, 2018

    @kemsky

    Is there any way disable this behavior without adding directive to every form in the application??

  6. StephenFluin commented on Mar 9, 2018

    @StephenFluin
    Contributor

    @kemsky In general our recommendation is to choose one forms technique. If you don't include FormsModule in your module, then the forms directives won't apply and native validation will work as-is. If you add FormsModule, most developers are looking to use the validation capabilities of the FormsModule, and use its status to manage the submission of forms. @kara might have other thoughts as well.

  7. kimamula commented on Dec 17, 2018

    @kimamula

    Is this still correct?

    Caution: Use these HTML5 validation attributes in combination with the built-in validators provided by Angular's reactive forms. Using these in combination prevents errors when the expression is changed after the template has been checked.

    https://angular.io/guide/reactive-forms#step-2-making-a-field-required

  8. wondering639 commented on Jul 15, 2019

    @wondering639

    Is this still correct?

    Caution: Use these HTML5 validation attributes in combination with the built-in validators provided by Angular's reactive forms. Using these in combination prevents errors when the expression is changed after the template has been checked.

    https://angular.io/guide/reactive-forms#step-2-making-a-field-required

    I doubt it: One can use the developer tools to see that even Angular 8 still adds novalidate to the form tag. So any validation isn't used anyways. Yet I'd also be happy about an official statement about this and a correction of the documentation.

  9. angular-automatic-lock-bot commented on Sep 15, 2019

    @angular-automatic-lock-bot

    This issue has been automatically locked due to inactivity.
    Please file a new issue if you are encountering a similar or related problem.

    Read more about our automatic conversation locking policy.

    This action has been performed automatically by a bot.

  10. locked and limited conversation to collaborators on Sep 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions