0
オートコンプリートフォームフィールド:上記のスニペットからカスタムフォームのエラー検証ビューで
<md-autocomplete
md-input-name="cityCode"
...
md-floating-label="Enter city code" required cityCodeInvalid>
<ng-messages="searchForm.cityCode.$error" ng-if="search.cityCode.$touched">
<div ng-message="required">City Code required</div>
<div ng-message="cityCodeInvalid">City code Invalid</div>
</ng-messages>
</md-autocomplete>
JSコード
var app = angular.module('MyApp',['ngMaterial', 'ngMessages']);
/*
My controller code:
app.controller.....
*/
app.directive('cityCodeInvalid', function() {
return {
restrict: "A",
require: "ngModel",
link: function(scope, element, attributes, ngModel) {
ngModel.$validators.cityCodeInvalid = function(modelValue) {
console.log("In custom validate function");
return true; /* forcibly returning true */
}
}
}
});
、私は、カスタムエラーMSGを作成しようとしていますmd-autocompleteフィールドの都市コード。私は都市コードの配列を持っているので、ユーザーが意図的に無効な都市コードを入力すると、「無効な都市コード」のメッセージが表示されます。
私のコードを参照してくださいカスタム関数(指示文で)がトリガーされたかどうかを確認するたびに、カスタム検証関数からtrueを返すようにしました。私は結果を見ない。
codepen/plunkrを入力してください。 – kuhnroyal