@darkobits/formation
Version:
56 lines (44 loc) • 2.66 kB
JavaScript
;
var _config = require('../../etc/config');
var _FormationControl2 = require('../../classes/FormationControl');
var _constants = require('../../etc/constants');
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; } // -----------------------------------------------------------------------------
// ----- Errors Component ------------------------------------------------------
// -----------------------------------------------------------------------------
/**
* This component is responsible for displaying errors related to a control.
*
* It implements the following bindings:
*
* - `for`: Control name to show errors for.
*
* @module Errors
*
* @example
*
* <fm name="myForm">
* <fm-input name="myControl"
* type="text">
* Enter some text:
* </fm-input>
* <fm-errors for="myControl"></fm-errors>
* </fm-form>
*/
var Errors = function (_FormationControl) {
_inherits(Errors, _FormationControl);
function Errors() {
_classCallCheck(this, Errors);
return _possibleConstructorReturn(this, (Errors.__proto__ || Object.getPrototypeOf(Errors)).apply(this, arguments));
}
return Errors;
}(_FormationControl2.FormationControl);
(0, _config.registerControl)('Errors', {
bindings: {
for: '@'
},
controller: Errors,
controllerAs: 'Errors',
template: '\n <label for="{{::Errors.$getCanonicalControlId() }}"\n ng-if="Errors.getErrors()"\n ng-class="{\n \'is-disabled\': Errors.isDisabled()\n }"\n ng-messages="Errors.getErrors()">\n <span ng-repeat="error in Errors.getErrorMessages()"\n ng-message="{{::error[0] }}">\n {{::error[1] }}\n </span>\n <span ng-message="' + _constants.CUSTOM_ERROR_KEY + '">\n {{ Errors.getCustomErrorMessage() }}\n </span>\n </label>\n '
});