e35a747e1b83a31b4d8f0f6f996dfdeabbfca810
[sdc.git] / catalog-ui / src / app / directives / custom-validation / custom-validation.ts
1 'use strict';
2 export interface ICustomValidationScope extends ng.IScope {
3     validationFunc:Function;
4 }
5
6 export class CustomValidationDirective implements ng.IDirective {
7
8     constructor() {
9     }
10
11     require = 'ngModel';
12     restrict = 'A';
13
14     scope = {
15         validationFunc: '='
16     };
17
18     link = (scope:ICustomValidationScope, elem, attrs, ngModel) => {
19
20         ngModel.$validators.customValidation = (modelValue, viewValue):boolean => {
21             return scope.validationFunc(viewValue);
22         };
23
24     };
25
26     public static factory = ()=> {
27         return new CustomValidationDirective();
28     };
29
30 }
31
32 CustomValidationDirective.factory.$inject = [];