Blame view

resources/js/common/directives/frHasError.js 817 Bytes
e77200db5   nologostudio.ru   Initial commit
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
  angular.module('fr.hasError', [])
  
  .directive('frHasError', ['$compile', function ($compile) {
      return {
          restrict: 'A',
          priority: 1000,
          terminal: true,
          compile: function (element, attrs) {
              element.removeAttr('fr-has-error');
  
              const onEvent = (attrs.onDirty !== undefined) ? '$dirty' : '$touched';
              const formCtrl = attrs.frHasError.substr(0, attrs.frHasError.lastIndexOf('.'));
  
              element.attr('ng-class',
                  "{ 'has-error': " + attrs.frHasError + '.$invalid && (' + attrs.frHasError + '.' + onEvent + ' || ' + formCtrl + '.$submitted ) }'
              );
  
              return {
                  post: function (scope, elem) {
                      $compile(elem)(scope);
                  },
              };
          },
      };
  }]);