UNPKG

angular2-schema-form

Version:

Angular2 Schema Form (DISCLAIMER: it is not related to angular-schema-form)

77 lines (76 loc) 2.92 kB
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 __()); }; })(); var Widget = (function () { function Widget() { this.id = ''; this.name = ''; this.schema = {}; } return Widget; }()); export { Widget }; var ControlWidget = (function (_super) { __extends(ControlWidget, _super); function ControlWidget() { return _super !== null && _super.apply(this, arguments) || this; } ControlWidget.prototype.ngAfterViewInit = function () { var _this = this; var control = this.control; this.formProperty.valueChanges.subscribe(function (newValue) { if (control.value !== newValue) { control.setValue(newValue, { emitEvent: false }); } }); this.formProperty.errorsChanges.subscribe(function (errors) { control.setErrors(errors, { emitEvent: true }); var messages = (errors || []) .filter(function (e) { return e.path && e.path.slice(1) === _this.formProperty.path; }) .map(function (e) { return e.message; }); _this.errorMessages = messages.filter(function (m, i) { return messages.indexOf(m) === i; }); }); control.valueChanges.subscribe(function (newValue) { _this.formProperty.setValue(newValue, false); }); }; return ControlWidget; }(Widget)); export { ControlWidget }; var ArrayLayoutWidget = (function (_super) { __extends(ArrayLayoutWidget, _super); function ArrayLayoutWidget() { return _super !== null && _super.apply(this, arguments) || this; } ArrayLayoutWidget.prototype.ngAfterViewInit = function () { var control = this.control; this.formProperty.errorsChanges.subscribe(function (errors) { control.setErrors(errors, { emitEvent: true }); }); }; return ArrayLayoutWidget; }(Widget)); export { ArrayLayoutWidget }; var ObjectLayoutWidget = (function (_super) { __extends(ObjectLayoutWidget, _super); function ObjectLayoutWidget() { return _super !== null && _super.apply(this, arguments) || this; } ObjectLayoutWidget.prototype.ngAfterViewInit = function () { var control = this.control; this.formProperty.errorsChanges.subscribe(function (errors) { control.setErrors(errors, { emitEvent: true }); }); }; return ObjectLayoutWidget; }(Widget)); export { ObjectLayoutWidget };