summaryrefslogtreecommitdiffstats
path: root/catalog-ui/src/app/directives/custom-validation/custom-validation.ts
blob: e35a747e1b83a31b4d8f0f6f996dfdeabbfca810 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
'use strict';
export interface ICustomValidationScope extends ng.IScope {
    validationFunc:Function;
}

export class CustomValidationDirective implements ng.IDirective {

    constructor() {
    }

    require = 'ngModel';
    restrict = 'A';

    scope = {
        validationFunc: '='
    };

    link = (scope:ICustomValidationScope, elem, attrs, ngModel) => {

        ngModel.$validators.customValidation = (modelValue, viewValue):boolean => {
            return scope.validationFunc(viewValue);
        };

    };

    public static factory = ()=> {
        return new CustomValidationDirective();
    };

}

CustomValidationDirective.factory.$inject = [];