Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Form submit preventing #15319

Closed
Closed

Description

What is the mechanism in AngularJS to avoid the submit state in forms? In others words, I want that a form prevents its default behaviour/state when submit button is clicked.

preventDefault and stopPropagation event methods are not useful.

Here is a CodePen example for fixing.

Activity

  1. gkalpak commented on Oct 27, 2016

    @gkalpak
    Member

    This sounds like a general support question. Please, use one of the appropriate support channels for these types of questions.
    GitHub issues are reserved for bug reports and feature requests.

    Thx!

  2. gkalpak commented on Oct 27, 2016

    @gkalpak
    Member

    There is a different listener on form/[ng-form] elements that calls formController.$setSubmitted(). The ngSubmit listener only gets executed after the listener that calls $setSubmitted(), so you can't stop that from ngSubmit. e.stopPropagation() does indeed prevent the submit event from propagating upwards, but $setSubmitted() also propagates upwards (and you haven't prevented that) - see #11023 for some discussion.

    If you want to be able to cancel both listeners, you need to set up your listener in the pre-linking function of a custom directive with a priority higher than ngSubmit/form/[ng-form].

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