UNPKG

novo-elements

Version:

Bullhorn's NOVO Element Repository for Angular 2

170 lines 6.36 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); // NG2 var forms_1 = require("@angular/forms"); var core_1 = require("@angular/core"); var NovoFormControl = (function (_super) { __extends(NovoFormControl, _super); function NovoFormControl(value, control) { var _this = _super.call(this, value, control.validators, control.asyncValidators) || this; _this.displayValueChanges = new core_1.EventEmitter(); _this.valueHistory = []; _this.validators = control.validators; _this.initialValue = value; _this.valueHistory.push(value); _this.label = control.label; _this.readOnly = control.readOnly; _this.hidden = control.hidden; _this.config = control.config; _this.type = control.type; _this.subType = control.subType; _this.required = control.required; _this.hasRequiredValidator = _this.required; _this.tooltip = control.tooltip; _this.tooltipPosition = control.tooltipPosition; _this.label = control.label; _this.name = control.name; _this.required = control.required; _this.hidden = control.hidden; _this.sortOrder = control.sortOrder; _this.controlType = control.controlType; _this.placeholder = control.placeholder; _this.multiple = control.multiple; _this.headerConfig = control.headerConfig; _this.optionsType = control.optionsType; _this.readOnly = control.readOnly; _this.layoutOptions = control.layoutOptions; _this.military = control.military; _this.maxlength = control.maxlength; _this.minlength = control.minlength; _this.closeOnSelect = control.closeOnSelect; _this.interactions = control.interactions; _this.appendToBody = control.appendToBody; _this.parentScrollSelector = control.parentScrollSelector; _this.description = control.description; _this.options = control.options; _this.tipWell = control.tipWell; // Reactive Form, need to enable/disable, can't bind to [disabled] if (_this.readOnly) { _this.disable(); } else { _this.enable(); } return _this; } /** * @name hide * @param clearValue - flag to reset the control's value */ NovoFormControl.prototype.hide = function (clearValue) { if (clearValue === void 0) { clearValue = true; } this.hidden = true; if (clearValue) { this.setValue(null); } }; /** * @name show */ NovoFormControl.prototype.show = function () { this.hidden = false; }; /** * @name setRequired * @param isRequired */ NovoFormControl.prototype.setRequired = function (isRequired) { this.required = isRequired; // Update validators to have the required if (this.required && !this.hasRequiredValidator) { var validators = this.validators.slice(); validators.push(forms_1.Validators.required); // TODO: duplicated below this.setValidators(validators); this.updateValueAndValidity(); this.hasRequiredValidator = this.required; } else if (!this.required && this.hasRequiredValidator) { var validators = this.validators.slice(); validators = validators.filter(function (val) { return val !== forms_1.Validators.required; }); // TODO: duplicated above this.setValidators(validators); this.updateValueAndValidity(); this.hasRequiredValidator = this.required; } }; /** * @name setValue * * @param value * @param onlySelf * @param emitEvent * @param emitModelToViewChange * @param emitViewToModelChange * */ NovoFormControl.prototype.setValue = function (value, _a) { var _this = this; var _b = _a === void 0 ? {} : _a, onlySelf = _b.onlySelf, emitEvent = _b.emitEvent, emitModelToViewChange = _b.emitModelToViewChange, emitViewToModelChange = _b.emitViewToModelChange; this.markAsDirty(); this.markAsTouched(); this.displayValueChanges.emit(value); _super.prototype.setValue.call(this, value, { onlySelf: onlySelf, emitEvent: emitEvent, emitModelToViewChange: emitModelToViewChange, emitViewToModelChange: emitViewToModelChange }); // History clearTimeout(this.historyTimeout); this.historyTimeout = setTimeout(function () { _this.valueHistory.push(value); }, 300); }; /** * @name setReadOnly * @param isReadOnly */ NovoFormControl.prototype.setReadOnly = function (isReadOnly) { this.readOnly = isReadOnly; if (this.readOnly) { this.disable(); } else { this.enable(); } }; /** * @name markAsInvalid * @param message */ NovoFormControl.prototype.markAsInvalid = function (message) { this.markAsDirty(); this.markAsTouched(); this.setErrors(Object.assign({}, this.errors, { custom: message })); }; return NovoFormControl; }(forms_1.FormControl)); exports.NovoFormControl = NovoFormControl; var NovoFormGroup = (function (_super) { __extends(NovoFormGroup, _super); function NovoFormGroup() { return _super !== null && _super.apply(this, arguments) || this; } Object.defineProperty(NovoFormGroup.prototype, "value", { get: function () { return this.getRawValue(); }, enumerable: true, configurable: true }); return NovoFormGroup; }(forms_1.FormGroup)); exports.NovoFormGroup = NovoFormGroup; //# sourceMappingURL=NovoFormControl.js.map