Code coverage report for src/form/form-group/form-group.component.js

Statements: 88.46% (23 / 26)      Branches: 64.71% (11 / 17)      Functions: 100% (5 / 5)      Lines: 88.46% (23 / 26)      Ignored: none     

All files » src/form/form-group/ » form-group.component.js
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 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 711                                   125   125 125         125 125 125   125 125     125 125     125 45     125 5       1 1907     1   125   125 125   125               125        
angular.module('patternfly.form').component('pfFormGroup', {
 
  bindings: {
    pfLabel: '@',
    pfField: '@',
    pfLabelClass: '@',
    pfInputClass: '@'
 
  },
  require: {
    form: '^form'
  },
  transclude: true,
  templateUrl: 'form/form-group/form-group.html',
 
  controller: function ($element) {
    'use strict';
 
    var ctrl = this;
 
    ctrl.$onInit = function () {
      angular.extend(ctrl, {
        hasErrors: hasErrors
      });
    };
 
    ctrl.$postLink = function () {
      var input = getInput($element);
      var type = input.attr('type');
 
      Eif (['checkbox', 'radio', 'time'].indexOf(type) === -1) {
        input.addClass('form-control');
      }
 
      Eif (!ctrl.pfField) {
        ctrl.pfField = input.attr('id');
      }
 
      if (input.attr('required')) {
        $element.addClass('required');
      }
 
      if (ctrl.form[ctrl.pfField]) {
        ctrl.error = ctrl.form[ctrl.pfField].$error;
      }
    };
 
    function hasErrors () {
      return ctrl.form[ctrl.pfField] && ctrl.form[ctrl.pfField].$invalid && ctrl.form[ctrl.pfField].$dirty;
    }
 
    function getInput (element) {
      // table is used for bootstrap3 date/time pickers
      var input = element.find('table');
 
      Eif (input.length === 0) {
        input = element.find('input');
 
        Iif (input.length === 0) {
          input = element.find('select');
 
          if (input.length === 0) {
            input = element.find('textarea');
          }
        }
      }
      return input;
    }
  }
});