﻿(function () {
    'use-strict';

    angular.module('judgeapp').directive('formLevelValidator', [formLevelValidator]);

    function formLevelValidator() {
        return {
            restrict: "A",
            require: "^form",
            link: (scope, IElement, iAttrs, ngForm) => {
                var validators = scope.$eval(iAttrs.formLevelValidator);

                Object.keys(validators).forEach(function (key) {
                    scope.$watch(validators[key], function (newValue) {
                        ngForm.$setValidity(key, newValue);
                    });
                });
            }
        };
    }
})();