3
我设置了一个表单来验证服务器端的OnBlur事件。服务器端验证工作正常,并按预期返回错误。但是,一旦将字段的有效性设置为false
,将其设置回true
不会消除$错误消息。是不是$ setValidity true应该从表单中删除错误?
这是控制器:
angular.module('artists').controller('ArtistsController', ['$scope', '$stateParams', '$location', 'Authentication', 'Artists',
function($scope, $stateParams, $location, Authentication, Artists) {
$scope.authentication = Authentication;
$scope.processForm = function(val){
var artist = new Artists({
name: $scope.artistForm.name.$viewValue,
quote: $scope.artistForm.quote.$viewValue
});
artist.$save(function(response) {
$scope.artistForm.$setValidity(val,true);
}, function(errorResponse) {
if(val in errorResponse.data){
$scope.artistForm.$setValidity(val,false,errorResponse.data[val].message);
}else{
$scope.artistForm.$setValidity(val,true);
}
});
};
}]);
我想'$ scope.artistForm $ setPristine()'会帮助你 –
setPristine是关系到“肮脏“或”未触动状态“的形式。它与错误验证不同。请参阅:http://stackoverflow.com/questions/17947639/removing-field-errors-when-setting-form-to-pristine-state –
什么是你的函数中的'val'? –