UNPKG

@ngx-formly/material

Version:

Formly is a dynamic (JSON powered) form library for Angular that bring unmatched maintainability to your application's forms.

206 lines (200 loc) 10.8 kB
import * as i0 from '@angular/core'; import { ViewChild, ChangeDetectionStrategy, Component, NgModule } from '@angular/core'; import * as i1 from '@ngx-formly/core'; import { ɵobserve as _observe, FormlyModule } from '@ngx-formly/core'; import { FieldType, FormlyMatFormFieldModule } from '@ngx-formly/material/form-field'; import * as i2 from '@angular/forms'; import { ReactiveFormsModule } from '@angular/forms'; import * as i3 from '@angular/material/input'; import { MatInputModule } from '@angular/material/input'; import * as i4 from '@angular/material/datepicker'; import { MatDatepickerModule } from '@angular/material/datepicker'; import { CommonModule } from '@angular/common'; class FormlyFieldDatepicker extends FieldType { constructor(config, cdRef) { super(); this.config = config; this.cdRef = cdRef; this.defaultOptions = { props: { datepickerOptions: { startView: 'month', datepickerTogglePosition: 'suffix', disabled: false, opened: false, dateInput: () => { }, dateChange: () => { }, monthSelected: () => { }, yearSelected: () => { }, }, }, }; } detectChanges() { this.options.detectChanges?.(this.field); } ngAfterViewInit() { this.props[this.props.datepickerOptions.datepickerTogglePosition] = this.datepickerToggle; _observe(this.field, ['props', 'datepickerOptions', 'opened'], () => { this.cdRef.detectChanges(); }); // temporary fix for https://github.com/angular/components/issues/16761 if (this.config.getValidatorMessage('matDatepickerParse')) { this.fieldErrorsObserver = _observe(this.field, ['formControl', 'errors'], ({ currentValue }) => { if (currentValue && currentValue.required && currentValue.matDatepickerParse) { const errors = Object.keys(currentValue) .sort((prop) => (prop === 'matDatepickerParse' ? -1 : 0)) .reduce((errors, prop) => ({ ...errors, [prop]: currentValue[prop] }), {}); this.fieldErrorsObserver?.setValue(errors); } }); } } ngOnDestroy() { super.ngOnDestroy(); this.fieldErrorsObserver?.unsubscribe(); } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: FormlyFieldDatepicker, deps: [{ token: i1.FormlyConfig }, { token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Component }); } static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "18.2.13", type: FormlyFieldDatepicker, selector: "formly-field-mat-datepicker", viewQueries: [{ propertyName: "datepickerToggle", first: true, predicate: ["datepickerToggle"], descendants: true, static: true }], usesInheritance: true, ngImport: i0, template: ` <input matInput [id]="id" [name]="field.name" [errorStateMatcher]="errorStateMatcher" [formControl]="formControl" [matDatepicker]="picker" [matDatepickerFilter]="props.datepickerOptions.filter" [max]="props.datepickerOptions.max" [min]="props.datepickerOptions.min" [formlyAttributes]="field" [placeholder]="props.placeholder" [tabindex]="props.tabindex" [readonly]="props.readonly" [required]="required" (dateInput)="props.datepickerOptions.dateInput(field, $event)" (dateChange)="props.datepickerOptions.dateChange(field, $event)" /> <ng-template #datepickerToggle> <mat-datepicker-toggle (click)="detectChanges()" [disabled]="props.disabled" [for]="picker" ></mat-datepicker-toggle> </ng-template> <mat-datepicker #picker [color]="props.color" [dateClass]="props.datepickerOptions.dateClass" [disabled]="props.datepickerOptions.disabled" [opened]="props.datepickerOptions.opened" [panelClass]="props.datepickerOptions.panelClass" [startAt]="props.datepickerOptions.startAt" [startView]="props.datepickerOptions.startView" [touchUi]="props.datepickerOptions.touchUi" [calendarHeaderComponent]="props.datepickerOptions.calendarHeaderComponent" (monthSelected)="props.datepickerOptions.monthSelected(field, $event, picker)" (yearSelected)="props.datepickerOptions.yearSelected(field, $event, picker)" (opened)="props.datepickerOptions.opened = true" (closed)="props.datepickerOptions.opened = false" > </mat-datepicker> `, isInline: true, dependencies: [{ kind: "directive", type: i2.DefaultValueAccessor, selector: "input:not([type=checkbox])[formControlName],textarea[formControlName],input:not([type=checkbox])[formControl],textarea[formControl],input:not([type=checkbox])[ngModel],textarea[ngModel],[ngDefaultControl]" }, { kind: "directive", type: i2.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i2.RequiredValidator, selector: ":not([type=checkbox])[required][formControlName],:not([type=checkbox])[required][formControl],:not([type=checkbox])[required][ngModel]", inputs: ["required"] }, { kind: "directive", type: i2.FormControlDirective, selector: "[formControl]", inputs: ["formControl", "disabled", "ngModel"], outputs: ["ngModelChange"], exportAs: ["ngForm"] }, { kind: "directive", type: i3.MatInput, selector: "input[matInput], textarea[matInput], select[matNativeControl], input[matNativeControl], textarea[matNativeControl]", inputs: ["disabled", "id", "placeholder", "name", "required", "type", "errorStateMatcher", "aria-describedby", "value", "readonly"], exportAs: ["matInput"] }, { kind: "component", type: i4.MatDatepicker, selector: "mat-datepicker", exportAs: ["matDatepicker"] }, { kind: "directive", type: i4.MatDatepickerInput, selector: "input[matDatepicker]", inputs: ["matDatepicker", "min", "max", "matDatepickerFilter"], exportAs: ["matDatepickerInput"] }, { kind: "component", type: i4.MatDatepickerToggle, selector: "mat-datepicker-toggle", inputs: ["for", "tabIndex", "aria-label", "disabled", "disableRipple"], exportAs: ["matDatepickerToggle"] }, { kind: "directive", type: i1.LegacyFormlyAttributes, selector: "[formlyAttributes]" }], changeDetection: i0.ChangeDetectionStrategy.OnPush }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: FormlyFieldDatepicker, decorators: [{ type: Component, args: [{ selector: 'formly-field-mat-datepicker', template: ` <input matInput [id]="id" [name]="field.name" [errorStateMatcher]="errorStateMatcher" [formControl]="formControl" [matDatepicker]="picker" [matDatepickerFilter]="props.datepickerOptions.filter" [max]="props.datepickerOptions.max" [min]="props.datepickerOptions.min" [formlyAttributes]="field" [placeholder]="props.placeholder" [tabindex]="props.tabindex" [readonly]="props.readonly" [required]="required" (dateInput)="props.datepickerOptions.dateInput(field, $event)" (dateChange)="props.datepickerOptions.dateChange(field, $event)" /> <ng-template #datepickerToggle> <mat-datepicker-toggle (click)="detectChanges()" [disabled]="props.disabled" [for]="picker" ></mat-datepicker-toggle> </ng-template> <mat-datepicker #picker [color]="props.color" [dateClass]="props.datepickerOptions.dateClass" [disabled]="props.datepickerOptions.disabled" [opened]="props.datepickerOptions.opened" [panelClass]="props.datepickerOptions.panelClass" [startAt]="props.datepickerOptions.startAt" [startView]="props.datepickerOptions.startView" [touchUi]="props.datepickerOptions.touchUi" [calendarHeaderComponent]="props.datepickerOptions.calendarHeaderComponent" (monthSelected)="props.datepickerOptions.monthSelected(field, $event, picker)" (yearSelected)="props.datepickerOptions.yearSelected(field, $event, picker)" (opened)="props.datepickerOptions.opened = true" (closed)="props.datepickerOptions.opened = false" > </mat-datepicker> `, changeDetection: ChangeDetectionStrategy.OnPush, }] }], ctorParameters: () => [{ type: i1.FormlyConfig }, { type: i0.ChangeDetectorRef }], propDecorators: { datepickerToggle: [{ type: ViewChild, args: ['datepickerToggle', { static: true }] }] } }); function withFormlyFieldDatepicker() { return { types: [ { name: 'datepicker', component: FormlyFieldDatepicker, wrappers: ['form-field'], }, ], }; } class FormlyMatDatepickerModule { static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: FormlyMatDatepickerModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); } static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "18.2.13", ngImport: i0, type: FormlyMatDatepickerModule, declarations: [FormlyFieldDatepicker], imports: [CommonModule, ReactiveFormsModule, MatInputModule, MatDatepickerModule, FormlyMatFormFieldModule, i1.FormlyModule] }); } static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: FormlyMatDatepickerModule, imports: [CommonModule, ReactiveFormsModule, MatInputModule, MatDatepickerModule, FormlyMatFormFieldModule, FormlyModule.forChild(withFormlyFieldDatepicker())] }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: FormlyMatDatepickerModule, decorators: [{ type: NgModule, args: [{ declarations: [FormlyFieldDatepicker], imports: [ CommonModule, ReactiveFormsModule, MatInputModule, MatDatepickerModule, FormlyMatFormFieldModule, FormlyModule.forChild(withFormlyFieldDatepicker()), ], }] }] }); /** * Generated bundle index. Do not edit. */ export { FormlyFieldDatepicker, FormlyMatDatepickerModule, withFormlyFieldDatepicker }; //# sourceMappingURL=ngx-formly-material-datepicker.mjs.map