ManageIQ/manageiq-ui-classic

View on GitHub
app/javascript/oldjs/directives/miqrequired.js

Summary

Maintainability
A
0 mins
Test Coverage
ManageIQ.angular.app.directive('miqrequired', function() {
  return {
    require: 'ngModel',
    link: function(scope, _elem, attrs, ctrl) {
      scope.$watch(attrs.ngModel, function() {
        if ((ctrl.$modelValue != undefined)) {
          setValidity(scope, ctrl, ctrl.$modelValue);
        }
      });
      ctrl.$parsers.push(function(value) {
        setValidity(scope, ctrl, ctrl.$viewValue);
        return value;
      });

      var setValidity = function(_scope, ctrl, value) {
        if (value !== '') {
          ctrl.$setValidity('miqrequired', true);
        } else {
          ctrl.$setValidity('miqrequired', false);
        }
      };
    },
  };
});