@ngx-formly/bootstrap
Version:
Formly is a dynamic (JSON powered) form library for Angular that bring unmatched maintainability to your application's forms.
236 lines (229 loc) • 11.3 kB
JavaScript
import * as i0 from '@angular/core';
import { Component, ChangeDetectionStrategy, ViewChild, NgModule } from '@angular/core';
import * as i1 from '@angular/common';
import { CommonModule } from '@angular/common';
import * as i2 from '@angular/forms';
import { SelectControlValueAccessor, ReactiveFormsModule } from '@angular/forms';
import * as i3 from '@ngx-formly/core';
import { FormlyModule } from '@ngx-formly/core';
import * as i4 from '@ngx-formly/core/select';
import { FormlySelectModule } from '@ngx-formly/core/select';
import { FieldType, FormlyBootstrapFormFieldModule } from '@ngx-formly/bootstrap/form-field';
import { take } from 'rxjs/operators';
class FormlyFieldSelect extends FieldType {
constructor(ngZone, hostContainerRef) {
super(hostContainerRef);
this.ngZone = ngZone;
this.defaultOptions = {
props: {
compareWith(o1, o2) {
return o1 === o2;
},
},
};
}
// workaround for https://github.com/angular/angular/issues/10010
/**
* TODO: Check if this is still needed
*/
set selectAccessor(s) {
if (!s) {
return;
}
const writeValue = s.writeValue.bind(s);
if (s._getOptionId(s.value) === null) {
writeValue(s.value);
}
s.writeValue = (value) => {
const id = s._idCounter;
writeValue(value);
if (value === null) {
this.ngZone.onStable
.asObservable()
.pipe(take(1))
.subscribe(() => {
if (id !== s._idCounter &&
s._getOptionId(value) === null &&
s._elementRef.nativeElement.selectedIndex !== -1) {
writeValue(value);
}
});
}
};
}
}
FormlyFieldSelect.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.12", ngImport: i0, type: FormlyFieldSelect, deps: [{ token: i0.NgZone }, { token: i0.ViewContainerRef }], target: i0.ɵɵFactoryTarget.Component });
FormlyFieldSelect.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.3.12", type: FormlyFieldSelect, selector: "formly-field-select", viewQueries: [{ propertyName: "selectAccessor", first: true, predicate: SelectControlValueAccessor, descendants: true }], usesInheritance: true, ngImport: i0, template: `
<ng-template #fieldTypeTemplate>
<select
*ngIf="props.multiple; else singleSelect"
class="form-select"
multiple
[formControl]="formControl"
[compareWith]="props.compareWith"
[class.is-invalid]="showError"
[formlyAttributes]="field"
[attr.aria-describedby]="id + '-formly-validation-error'"
[attr.aria-invalid]="showError"
>
<ng-container *ngIf="props.options | formlySelectOptions : field | async as opts">
<ng-container *ngFor="let opt of opts">
<option *ngIf="!opt.group; else optgroup" [ngValue]="opt.value" [disabled]="opt.disabled">
{{ opt.label }}
</option>
<ng-template #optgroup>
<optgroup [label]="opt.label">
<option *ngFor="let child of opt.group" [ngValue]="child.value" [disabled]="child.disabled">
{{ child.label }}
</option>
</optgroup>
</ng-template>
</ng-container>
</ng-container>
</select>
<ng-template #singleSelect>
<select
class="form-select"
[formControl]="formControl"
[compareWith]="props.compareWith"
[class.is-invalid]="showError"
[formlyAttributes]="field"
[attr.aria-describedby]="id + '-formly-validation-error'"
[attr.aria-invalid]="showError"
>
<option *ngIf="props.placeholder" [ngValue]="undefined">{{ props.placeholder }}</option>
<ng-container *ngIf="props.options | formlySelectOptions : field | async as opts">
<ng-container *ngFor="let opt of opts">
<option *ngIf="!opt.group; else optgroup" [ngValue]="opt.value" [disabled]="opt.disabled">
{{ opt.label }}
</option>
<ng-template #optgroup>
<optgroup [label]="opt.label">
<option *ngFor="let child of opt.group" [ngValue]="child.value" [disabled]="child.disabled">
{{ child.label }}
</option>
</optgroup>
</ng-template>
</ng-container>
</ng-container>
</select>
</ng-template>
</ng-template>
`, isInline: true, directives: [{ type: i1.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { type: i2.SelectMultipleControlValueAccessor, selector: "select[multiple][formControlName],select[multiple][formControl],select[multiple][ngModel]", inputs: ["compareWith"] }, { type: i2.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { type: i2.FormControlDirective, selector: "[formControl]", inputs: ["formControl", "disabled", "ngModel"], outputs: ["ngModelChange"], exportAs: ["ngForm"] }, { type: i3.ɵFormlyAttributes, selector: "[formlyAttributes]", inputs: ["formlyAttributes", "id"] }, { type: i1.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { type: i2.NgSelectOption, selector: "option", inputs: ["ngValue", "value"] }, { type: i2.ɵNgSelectMultipleOption, selector: "option", inputs: ["ngValue", "value"] }, { type: i2.SelectControlValueAccessor, selector: "select:not([multiple])[formControlName],select:not([multiple])[formControl],select:not([multiple])[ngModel]", inputs: ["compareWith"] }], pipes: { "async": i1.AsyncPipe, "formlySelectOptions": i4.FormlySelectOptionsPipe }, changeDetection: i0.ChangeDetectionStrategy.OnPush });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.12", ngImport: i0, type: FormlyFieldSelect, decorators: [{
type: Component,
args: [{
selector: 'formly-field-select',
template: `
<ng-template #fieldTypeTemplate>
<select
*ngIf="props.multiple; else singleSelect"
class="form-select"
multiple
[formControl]="formControl"
[compareWith]="props.compareWith"
[class.is-invalid]="showError"
[formlyAttributes]="field"
[attr.aria-describedby]="id + '-formly-validation-error'"
[attr.aria-invalid]="showError"
>
<ng-container *ngIf="props.options | formlySelectOptions : field | async as opts">
<ng-container *ngFor="let opt of opts">
<option *ngIf="!opt.group; else optgroup" [ngValue]="opt.value" [disabled]="opt.disabled">
{{ opt.label }}
</option>
<ng-template #optgroup>
<optgroup [label]="opt.label">
<option *ngFor="let child of opt.group" [ngValue]="child.value" [disabled]="child.disabled">
{{ child.label }}
</option>
</optgroup>
</ng-template>
</ng-container>
</ng-container>
</select>
<ng-template #singleSelect>
<select
class="form-select"
[formControl]="formControl"
[compareWith]="props.compareWith"
[class.is-invalid]="showError"
[formlyAttributes]="field"
[attr.aria-describedby]="id + '-formly-validation-error'"
[attr.aria-invalid]="showError"
>
<option *ngIf="props.placeholder" [ngValue]="undefined">{{ props.placeholder }}</option>
<ng-container *ngIf="props.options | formlySelectOptions : field | async as opts">
<ng-container *ngFor="let opt of opts">
<option *ngIf="!opt.group; else optgroup" [ngValue]="opt.value" [disabled]="opt.disabled">
{{ opt.label }}
</option>
<ng-template #optgroup>
<optgroup [label]="opt.label">
<option *ngFor="let child of opt.group" [ngValue]="child.value" [disabled]="child.disabled">
{{ child.label }}
</option>
</optgroup>
</ng-template>
</ng-container>
</ng-container>
</select>
</ng-template>
</ng-template>
`,
changeDetection: ChangeDetectionStrategy.OnPush,
}]
}], ctorParameters: function () { return [{ type: i0.NgZone }, { type: i0.ViewContainerRef }]; }, propDecorators: { selectAccessor: [{
type: ViewChild,
args: [SelectControlValueAccessor]
}] } });
class FormlyBootstrapSelectModule {
}
FormlyBootstrapSelectModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.12", ngImport: i0, type: FormlyBootstrapSelectModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
FormlyBootstrapSelectModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "13.3.12", ngImport: i0, type: FormlyBootstrapSelectModule, declarations: [FormlyFieldSelect], imports: [CommonModule,
ReactiveFormsModule,
FormlyBootstrapFormFieldModule,
FormlySelectModule, i3.FormlyModule] });
FormlyBootstrapSelectModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "13.3.12", ngImport: i0, type: FormlyBootstrapSelectModule, imports: [[
CommonModule,
ReactiveFormsModule,
FormlyBootstrapFormFieldModule,
FormlySelectModule,
FormlyModule.forChild({
types: [
{
name: 'select',
component: FormlyFieldSelect,
wrappers: ['form-field'],
},
{ name: 'enum', extends: 'select' },
],
}),
]] });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.12", ngImport: i0, type: FormlyBootstrapSelectModule, decorators: [{
type: NgModule,
args: [{
declarations: [FormlyFieldSelect],
imports: [
CommonModule,
ReactiveFormsModule,
FormlyBootstrapFormFieldModule,
FormlySelectModule,
FormlyModule.forChild({
types: [
{
name: 'select',
component: FormlyFieldSelect,
wrappers: ['form-field'],
},
{ name: 'enum', extends: 'select' },
],
}),
],
}]
}] });
/**
* Generated bundle index. Do not edit.
*/
export { FormlyBootstrapSelectModule, FormlyFieldSelect };
//# sourceMappingURL=ngx-formly-bootstrap-select.mjs.map