カスタム非同期バリデータを含むフォームがあります。入力フィールドの値が無効な場合でも、エラー メッセージが表示されない場合があることに気付きました。
通常のバリデーターで問題を再現できました: codepen の例
HTML:
<div ng-app="app" ng-controller="FormController" layout-padding>
<form name="inputForm">
<md-input-container>
<input type="text" name="inputValue" custom-validator ng-model="model.value" />
<label>input value</label>
<div ng-messages="inputForm.inputValue.$error">
<div ng-message="custom-validator">This field is invalid</div>
</div>
</md-input-container>
<div>inputForm.inputValue.$error = {{inputForm.inputValue.$error | json}}</div>
</div>
JS:
var app = angular.module('app', ['ngMaterial', 'ngMessages']);
app.controller('FormController', ['$scope', function($scope) {
$scope.model = {
value: '',
asyncValue: ''
}
}]);
app.directive('customValidator', function() {
return {
require: 'ngModel',
link: function (scope, element, attr, ctrl) {
ctrl.$validators['custom-validator'] = function(model, view) {
return (model.length % 2) == 0;
}
}
}
})
値をゆっくり入力すると、エラー メッセージが正しく表示されて消えます。しかし、入力が無効であっても、すばやく入力するとエラーメッセージが消えます。エラー メッセージのアニメーションが進行中に $error の値が変化すると、問題が発生するようです。
私が間違ったことはありますか?