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 and input is getting dirty by clicking on a simple button #7457

Closed

Description

@westor21

Create a simple form with an input and a button without any functionality. Clicking the button results in setting the form and the input to dirty.
To illustrate the behaviour I made a plunkr:
http://plnkr.co/edit/GlLD83K8OLVIShPlfENm?p=preview
Best regards
westor21

Activity

  1. caitp commented on May 14, 2014

    @caitp
    Contributor

    http://www.whatwg.org/specs/web-apps/current-work/multipage/the-button-element.html#attr-button-type

    The type attribute controls the behavior of the button when it is activated. It is an enumerated attribute. The following table lists the keywords and states for the attribute — the keywords in the left column map to the states in the cell in the second column on the same row as the keyword.

    Keyword State Brief description
    submit Submit Button Submits the form.
    reset Reset Button Resets the form.
    button Button Does nothing.
    menu Menu Shows a menu.

    The missing value default is the Submit Button state.

    If the type attribute is in the Submit Button state, the element is specifically a submit button.

    Basically, when you don't give your button a type, it defaults to "submit", and angular's submission handler causes the form to be dirty'd.

    You have an easy work around, just give the button a type, like type="button", that should prevent form submission and avoid dirtying the form/model controllers.

    @petebacondarwin / @matsko should we be dirtying the form on submit if it doesn't change? that seems weird.

  2. added this to the milestone on May 15, 2014
  3. westor21 commented on May 15, 2014

    @westor21
    Author

    Thank you for your answer. And yes, that seems to be not the expected behaviour to me. We are setting classes in dependence a form element is touched by the user. Therefore it seems to be weird to set the form and the elements dirty if nothing was edited.

  4. self-assigned this
    on May 15, 2014
  5. shahata commented on May 16, 2014

    @shahata
    Contributor

    @caitp @petebacondarwin the form is becoming dirty due my bug in a0ae07b ($commitViewValue always sets the control as dirty and now it is called with every submit). I'll take a look into this.

  6. petebacondarwin commented on May 16, 2014

    @petebacondarwin
    Contributor

    Thanks @shahata

  7. added a commit that references this issue on May 24, 2014
    f439c0a
  8. NaomiN commented on Sep 20, 2017

    @NaomiN

    I am using angular-js 1.6.4 and I am getting the same problem. May be the issue re-appeared. I fixed it by setting my buttons type to be button instead of submit, but the issue marked as closed so I should not need to have done it, right?

  9. petebacondarwin commented on Sep 20, 2017

    @petebacondarwin
    Contributor

    @NaomiN the original issue is not broken with 1.6.4. See http://plnkr.co/edit/EAAdJScYtRJKich5FJQs?p=preview

    If you are experiencing a different issue then please can you create a new issue with a reproduction.

  10. NaomiN commented on Sep 20, 2017

    @NaomiN

    In the original plunker I made a single change - the input type="number" to demonstrate the problem. The problem only shows for input type="number" and buttons. I made a google search and found this issue. So my solution was to use button type="button"

  11. petebacondarwin commented on Sep 20, 2017

    @petebacondarwin
    Contributor

    I just tried that on my new plunker and it still doesn't mark it as dirty.

  12. NaomiN commented on Sep 20, 2017

    @NaomiN

    Weird, I can no longer reproduce myself there even though it marked as dirty this morning. I know I spent several hours last night trying to figure out the problem with my form before landing on this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions