ng-bootstrap-form-generator
Version:
Angular 2 + Bootstrap 4 Form Generator. Library provides Angular components that help quickly generate Bootstrap Form from JavaScript object. Component supports validators, help messages, and error messages.
249 lines • 13 kB
JavaScript
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
import { Component, Directive, Input, Output, EventEmitter, ChangeDetectionStrategy, ChangeDetectorRef } from '@angular/core';
import { FormGroup } from '@angular/forms';
import { BsfControl } from './bsf.control';
export var BsfGroupCustomContentComponent = (function () {
function BsfGroupCustomContentComponent() {
}
BsfGroupCustomContentComponent = __decorate([
Component({ selector: 'bsf-before,bsf-after', template: '<ng-content></ng-content>' }),
__metadata('design:paramtypes', [])
], BsfGroupCustomContentComponent);
return BsfGroupCustomContentComponent;
}());
export var BsfGroupComponent = (function () {
function BsfGroupComponent(_cd) {
this._cd = _cd;
this.bsfControls = [];
this.valueChange = new EventEmitter();
}
Object.defineProperty(BsfGroupComponent.prototype, "options", {
get: function () { return this._options; },
set: function (value) {
this.initFormGroup(value);
this._options = value;
this._cd.markForCheck();
},
enumerable: true,
configurable: true
});
;
Object.defineProperty(BsfGroupComponent.prototype, "value", {
get: function () { return this.form ? this.form.value : null; },
set: function (value) {
this.form.patchValue(value, { onlySelf: true, emitEvent: true });
this._cd.markForCheck();
},
enumerable: true,
configurable: true
});
;
BsfGroupComponent.prototype.ngOnInit = function () {
};
BsfGroupComponent.prototype.initFormGroup = function (options) {
var formControls = {};
for (var _i = 0, options_1 = options; _i < options_1.length; _i++) {
var controlOptions = options_1[_i];
var control = new BsfControl(controlOptions);
// Radio inputs should have same field name to be grouped
// Override FormControls that have same name
// Create all bfsControl for render.
control.fc = formControls[control.field] || control.fc;
formControls[control.field] = control.fc;
this.bsfControls.push(control);
}
this.form = new FormGroup(formControls);
this.form.valueChanges.subscribe(this.valueChange);
};
__decorate([
Input(),
__metadata('design:type', Array)
], BsfGroupComponent.prototype, "options", null);
__decorate([
Input(),
__metadata('design:type', Object)
], BsfGroupComponent.prototype, "value", null);
__decorate([
Output(),
__metadata('design:type', EventEmitter)
], BsfGroupComponent.prototype, "valueChange", void 0);
BsfGroupComponent = __decorate([
Component({
selector: 'bsf-form',
template: "\n <div [formGroup]=\"form\" >\n <ng-content select=\"bsf-before\"></ng-content>\n <template ngFor let-control [ngForOf]='bsfControls'>\n <div [ngSwitch]=\"control.type\">\n <bsf-hidden *ngSwitchCase=\"'hidden'\" [control]='control' [form]='form'> </bsf-hidden>\n <bsf-checkbox *ngSwitchCase=\"'checkbox'\" [control]='control' [form]='form'> </bsf-checkbox>\n <!-- <bsf-radio *ngSwitchCase=\"'radio'\" [control]='control' [form]='form'> </bsf-radio>-->\n <bsf-select *ngSwitchCase=\"'select'\" [control]='control' [form]='form'> </bsf-select>\n <bsf-input *ngSwitchDefault [control]='control' [form]='form'></bsf-input>\n </div>\n </template >\n <ng-content select=\"bsf-after\"></ng-content>\n </div>\n",
changeDetection: ChangeDetectionStrategy.OnPush
}),
__metadata('design:paramtypes', [ChangeDetectorRef])
], BsfGroupComponent);
return BsfGroupComponent;
}());
export var BsfBaseControlComponent = (function () {
function BsfBaseControlComponent(_cd) {
this._cd = _cd;
}
BsfBaseControlComponent.prototype.ngOnInit = function () {
var _this = this;
this._prev = this.c.fc.value;
this.c.fc.valueChanges.subscribe(function (next) {
if (next !== _this._prev) {
_this._prev = next;
_this._cd.markForCheck();
}
});
};
__decorate([
Input('control'),
__metadata('design:type', BsfControl)
], BsfBaseControlComponent.prototype, "c", void 0);
BsfBaseControlComponent = __decorate([
Component({
selector: 'bsf-control',
template: "\n <div class=\"form-group\"\n [class.has-danger] = '!c.fc.valid && !c.disabled && !c.fc.pristine'\n [class.has-success] = 'c.fc.valid && !c.disabled && c.fc.validator'>\n\n <ng-content></ng-content>\n\n\n <div *ngFor='let error of c.errors' class=\"form-control-feedback\">{{error}}</div>\n <small [id]='c.field + \"-help-text\"' class=\"form-text text-muted\" *ngIf='c.helpText' >{{c.helpText}}</small>\n <small [id]='c.field + \"-help-text\"' class=\"form-text text-muted\" *ngIf='!c.helpText && c.helpTextHtml' \n [innerHTML]='c.helpTextHtml'></small>\n </div>\n",
changeDetection: ChangeDetectionStrategy.OnPush
}),
__metadata('design:paramtypes', [ChangeDetectorRef])
], BsfBaseControlComponent);
return BsfBaseControlComponent;
}());
export var BsfInputControlComponent = (function () {
function BsfInputControlComponent() {
}
__decorate([
Input('control'),
__metadata('design:type', BsfControl)
], BsfInputControlComponent.prototype, "c", void 0);
__decorate([
Input(),
__metadata('design:type', FormGroup)
], BsfInputControlComponent.prototype, "form", void 0);
BsfInputControlComponent = __decorate([
Component({
selector: 'bsf-input',
template: "\n <bsf-control [control]='c' [formGroup]='form'>\n <label [for]='c.field' >{{c.title}}</label>\n <input class=\"form-control\" [bsfControl]='c' [formControlName]='c.field' [type]='c.type' [placeholder]='c.placeholder' >\n </bsf-control>\n",
changeDetection: ChangeDetectionStrategy.OnPush
}),
__metadata('design:paramtypes', [])
], BsfInputControlComponent);
return BsfInputControlComponent;
}());
export var BsfHiddenInputControlComponent = (function () {
function BsfHiddenInputControlComponent() {
}
__decorate([
Input('control'),
__metadata('design:type', BsfControl)
], BsfHiddenInputControlComponent.prototype, "c", void 0);
__decorate([
Input(),
__metadata('design:type', FormGroup)
], BsfHiddenInputControlComponent.prototype, "form", void 0);
BsfHiddenInputControlComponent = __decorate([
Component({
selector: 'bsf-hidden',
template: "\n <div [formGroup]='form'>\n <input class=\"form-control\" [bsfControl]='c' [formControlName]='c.field' type='hidden'>\n </div>\n",
changeDetection: ChangeDetectionStrategy.OnPush
}),
__metadata('design:paramtypes', [])
], BsfHiddenInputControlComponent);
return BsfHiddenInputControlComponent;
}());
export var BsfCheckboxControlComponent = (function () {
function BsfCheckboxControlComponent() {
}
__decorate([
Input('control'),
__metadata('design:type', BsfControl)
], BsfCheckboxControlComponent.prototype, "c", void 0);
__decorate([
Input(),
__metadata('design:type', FormGroup)
], BsfCheckboxControlComponent.prototype, "form", void 0);
BsfCheckboxControlComponent = __decorate([
Component({
selector: 'bsf-checkbox',
template: "\n <bsf-control [control]='c' [formGroup]='form'>\n <label [for]='c.field' class='custom-control custom-checkbox'>\n <input class=\"custom-control-input\" [bsfControl]='c' [formControlName]='c.field' type='checkbox' >\n <span class=\"custom-control-indicator\"></span>\n <span class=\"custom-control-description\">{{c.title}}</span>\n </label>\n </bsf-control>\n",
changeDetection: ChangeDetectionStrategy.OnPush
}),
__metadata('design:paramtypes', [])
], BsfCheckboxControlComponent);
return BsfCheckboxControlComponent;
}());
// TODO: Implement. After add 'radio' InputType and uncomment ngSwitch in BsfGroupComponent template
export var BsfRadioControlComponent = (function () {
function BsfRadioControlComponent() {
}
BsfRadioControlComponent.prototype.ngOnInit = function () {
this.c.elId = this.c.elId + '-' + this.c.defaultValue;
};
__decorate([
Input('control'),
__metadata('design:type', BsfControl)
], BsfRadioControlComponent.prototype, "c", void 0);
__decorate([
Input(),
__metadata('design:type', FormGroup)
], BsfRadioControlComponent.prototype, "form", void 0);
BsfRadioControlComponent = __decorate([
Component({
selector: 'bsf-radio',
template: "\n <bsf-control [control]='c' [formGroup]='form'>\n <label [for]='c.field' class='custom-control custom-radio'>\n <input class=\"custom-control-input\" [bsfControl]='c' [formControlName]='c.field' type='radio' >\n <span class=\"custom-control-indicator\"></span>\n <span class=\"custom-control-description\">{{c.title}}</span>\n </label>\n </bsf-control>\n",
changeDetection: ChangeDetectionStrategy.OnPush
}),
__metadata('design:paramtypes', [])
], BsfRadioControlComponent);
return BsfRadioControlComponent;
}());
export var BsfSelectControlComponent = (function () {
function BsfSelectControlComponent() {
}
__decorate([
Input('control'),
__metadata('design:type', BsfControl)
], BsfSelectControlComponent.prototype, "c", void 0);
__decorate([
Input(),
__metadata('design:type', FormGroup)
], BsfSelectControlComponent.prototype, "form", void 0);
BsfSelectControlComponent = __decorate([
Component({
selector: 'bsf-select',
template: "\n <bsf-control [control]='c' [formGroup]='form'>\n <label [for]='c.field'>{{c.title}}</label>\n <select class=\"form-control custom-select\" [bsfControl]='c' [formControlName]='c.field'>\n <option *ngIf='c.select.emptyText' \n [attr.disabled] = 'c.required ? \"\" : null'\n [attr.selected] = 'c.fc.value === \"\" ? \"\" : null'\n value=''> {{ c.select.emptyText}} </option>\n <option *ngFor='let opt of c.select.options' [value]=\"opt.value\" \n [attr.selected] ='opt.value === c.fc.value ? \"\" : null'>{{opt.text}}</option>\n </select>\n </bsf-control>\n",
changeDetection: ChangeDetectionStrategy.OnPush
}),
__metadata('design:paramtypes', [])
], BsfSelectControlComponent);
return BsfSelectControlComponent;
}());
export var BsfControlDirective = (function () {
function BsfControlDirective() {
}
__decorate([
Input('bsfControl'),
__metadata('design:type', BsfControl)
], BsfControlDirective.prototype, "c", void 0);
BsfControlDirective = __decorate([
Directive({
selector: '[bsfControl]',
host: {
'[id]': 'c.elId',
'[name]': 'c.field',
'[class.form-control-danger]': '!c.fc.valid',
'[class.form-control-success]': 'c.fc.valid && c.fc.validator',
'[attr.aria-describedby]': 'c.field + "-help-text"',
'[attr.disabled]': 'c.disabled',
'[attr.required]': 'c.required',
}
}),
__metadata('design:paramtypes', [])
], BsfControlDirective);
return BsfControlDirective;
}());
//# sourceMappingURL=bsf.components.js.map