UNPKG

@darkobits/formation

Version:
68 lines (57 loc) 3.94 kB
'use strict'; var _config = require('../../etc/config'); var _constants = require('../../etc/constants'); var _FormationControl2 = require('../../classes/FormationControl'); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } // ----------------------------------------------------------------------------- // ----- Input Component ------------------------------------------------------- // ----------------------------------------------------------------------------- /** * This component creates an input control and a label. All valid HTML5 input * types are allowed. The label is transcluded. * * Note: For "radio" and "checkbox" types, the label will be * rendered after the control. For all other types, the label will be rendered * before the control. * * Implements the following bindings: * - `config`: Configuration object. * - `name`: Name of the control. * - `placeholder`: Control placeholder. * - `type`: Control type. * - `ng-disabled`: If truthy, will disable the control. * - `ng-value`: Value to assign to model value (for radio buttons). * * @module Input * * @example * * <my-form name="myForm"> * <my-input name="myControl" * type="text" * config="vm.myControlConfig"> * Enter some text: * </my-input> * </my-form> */ var InputControl = function (_FormationControl) { _inherits(InputControl, _FormationControl); function InputControl() { _classCallCheck(this, InputControl); return _possibleConstructorReturn(this, (InputControl.__proto__ || Object.getPrototypeOf(InputControl)).apply(this, arguments)); } return InputControl; }(_FormationControl2.FormationControl); (0, _config.registerControl)('Input', { bindings: { name: '@', placeholder: '@', type: '@', ngValue: '<' }, transclude: true, controller: InputControl, controllerAs: 'Input', template: '\n <label for="{{::Input.getControlId() }}"\n ng-if="Input.type !== \'radio\' && Input.type !== \'checkbox\'"\n ng-class="{\n \'has-error\': Input.getErrors(),\n \'is-pending\': Input.' + _constants.NG_MODEL_CTRL + '.$pending,\n \'is-disabled\': Input.isDisabled()\n }"\n ng-transclude>\n </label>\n <input id="{{::Input.getControlId() }}"\n type="{{::Input.type }}"\n name="{{::Input.type === \'radio\' ? Input.$getFormName() + \'-\' + Input.name : Input.name }}"\n placeholder="{{::Input.placeholder }}"\n ng-model="Input.$ngModelGetterSetter"\n ng-value="Input.ngValue"\n ng-class="{\n \'has-error\': Input.getErrors(),\n \'is-pending\': Input.' + _constants.NG_MODEL_CTRL + '.$pending,\n \'is-disabled\': Input.isDisabled()\n }"\n ng-disabled="Input.isDisabled()">\n <label for="{{::Input.getControlId() }}"\n ng-if="Input.type === \'radio\' || Input.type === \'checkbox\'"\n ng-class="{\n \'has-error\': Input.getErrors(),\n \'is-pending\': Input.' + _constants.NG_MODEL_CTRL + '.$pending,\n \'is-disabled\': Input.isDisabled()\n }"\n ng-transclude>\n </label>\n ' });