mirror of
https://github.com/bitwarden/web
synced 2025-12-06 00:03:28 +00:00
30 lines
861 B
JavaScript
30 lines
861 B
JavaScript
angular
|
|
.module('bit.directives')
|
|
|
|
.directive('apiField', function () {
|
|
var linkFn = function (scope, element, attrs, ngModel) {
|
|
ngModel.$registerApiError = registerApiError;
|
|
ngModel.$validators.apiValidate = apiValidator;
|
|
|
|
function apiValidator() {
|
|
ngModel.$setValidity('api', true);
|
|
return true;
|
|
}
|
|
|
|
function registerApiError() {
|
|
ngModel.$setValidity('api', false);
|
|
}
|
|
};
|
|
|
|
return {
|
|
require: 'ngModel',
|
|
restrict: 'A',
|
|
compile: function (elem, attrs) {
|
|
if (!attrs.name || attrs.name === '') {
|
|
throw 'api-field element does not have a valid name attribute';
|
|
}
|
|
|
|
return linkFn;
|
|
}
|
|
};
|
|
}); |