You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
Repository navigation
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
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
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.
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.
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.
@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.
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?
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"
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.
Activity
caitp commentedon May 14, 2014
http://www.whatwg.org/specs/web-apps/current-work/multipage/the-button-element.html#attr-button-type
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.
westor21 commentedon May 15, 2014
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.
shahata commentedon May 16, 2014
@caitp @petebacondarwin the form is becoming dirty due my bug in a0ae07b (
$commitViewValuealways sets the control as dirty and now it is called with every submit). I'll take a look into this.petebacondarwin commentedon May 16, 2014
Thanks @shahata
fix(ngModel): do not dirty the input on $commitViewValue if nothing w…
NaomiN commentedon Sep 20, 2017
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?
petebacondarwin commentedon Sep 20, 2017
@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.
NaomiN commentedon Sep 20, 2017
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"
petebacondarwin commentedon Sep 20, 2017
I just tried that on my new plunker and it still doesn't mark it as dirty.
NaomiN commentedon Sep 20, 2017
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.