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.
I wan to show the error message when the user submit an invalid and pristine form.
I use the following css selector to style the message, since that I don't wan to show message if the form is pristine.
.ng-dirty.ng-invalid {
border-color:red;
xxx
}
So I do some check in the form submit callbak (ngSubmit), if the form is invalid, I wan to manually set the error control to dirty state, so that the css selector which is .ng-dirty.ng-invalid work.
$scope.doSubmit=function(){if($scope.theForm.$invalid){Object.keys($scope.theForm.$error).forEach(function(key){$scope.theForm.$error[key].forEach(function(control){control.$setDirty();// no $setDirty function});});return;}// ajax submit// ...}
There is $setDiry function in FormController, but I can't use it, because the function only add ng-dirty class to form element, if I use selector .ng-dirty .ng-invalid insteaded, it will apply to too much input element that all the error message come out if any input change.
I found the $setPristine function in input directive, I think it should provide $setDirty too.
The text was updated successfully, but these errors were encountered:
tobyee
changed the title
$setDirty function should provided by the controller of input directive
$setDirty function should provided by the controller of ng-model directive
Nov 13, 2014
Looking at the code for $setPristine, it doesn't look very complicated, so $setDirty would probably be similar, except that it needs to set the parentForm to $dirty, too. If it's just that I think it's okay to have it. Consistency with FormController is also nice to have.
I wan to show the error message when the user submit an invalid and pristine form.
I use the following css selector to style the message, since that I don't wan to show message if the form is pristine.
So I do some check in the form submit callbak (
ngSubmit
), if the form is invalid, I wan to manually set the error control to dirty state, so that the css selector which is.ng-dirty.ng-invalid
work.There is
$setDiry
function inFormController
, but I can't use it, because the function only addng-dirty
class to form element, if I use selector.ng-dirty .ng-invalid
insteaded, it will apply to too much input element that all the error message come out if any input change.I found the
$setPristine
function in input directive, I think it should provide$setDirty
too.The text was updated successfully, but these errors were encountered: