UNPKG

@ngx-formly/material

Version:

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

138 lines (132 loc) 6.75 kB
import * as i0 from '@angular/core'; import { ViewChildren, ChangeDetectionStrategy, Component, NgModule } from '@angular/core'; import * as i1 from '@angular/material/checkbox'; import { MatCheckbox, MatCheckboxModule } from '@angular/material/checkbox'; import { FieldType, FormlyMatFormFieldModule } from '@ngx-formly/material/form-field'; import * as i2 from '@ngx-formly/core'; import { FormlyModule } from '@ngx-formly/core'; import * as i3 from '@angular/common'; import { CommonModule } from '@angular/common'; import * as i4 from '@ngx-formly/core/select'; import { FormlySelectModule } from '@ngx-formly/core/select'; import { ReactiveFormsModule } from '@angular/forms'; class FormlyFieldMultiCheckbox extends FieldType { constructor() { super(...arguments); this.defaultOptions = { props: { hideFieldUnderline: true, floatLabel: 'always', color: 'accent', // workaround for https://github.com/angular/components/issues/18465 }, }; } onChange(value, checked) { this.formControl.markAsDirty(); if (this.props.type === 'array') { this.formControl.patchValue(checked ? [...(this.formControl.value || []), value] : [...(this.formControl.value || [])].filter((o) => o !== value)); } else { this.formControl.patchValue({ ...this.formControl.value, [value]: checked }); } this.formControl.markAsTouched(); } // TODO: find a solution to prevent scroll on focus onContainerClick() { } isChecked(option) { const value = this.formControl.value; return value && (this.props.type === 'array' ? value.indexOf(option.value) !== -1 : value[option.value]); } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: FormlyFieldMultiCheckbox, deps: null, target: i0.ɵɵFactoryTarget.Component }); } static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "18.2.13", type: FormlyFieldMultiCheckbox, selector: "formly-field-mat-multicheckbox", host: { properties: { "id": "id" } }, viewQueries: [{ propertyName: "checkboxes", predicate: MatCheckbox, descendants: true }], usesInheritance: true, ngImport: i0, template: ` @for (option of props.options | formlySelectOptions: field | async; track $index; let i = $index) { <mat-checkbox [id]="id + '_' + i" [formlyAttributes]="field" [tabIndex]="props.tabindex" [color]="props.color" [labelPosition]="props.labelPosition" [checked]="isChecked(option)" [disabled]="formControl.disabled || option.disabled" (change)="onChange(option.value, $event.checked)" > {{ option.label }} </mat-checkbox> } `, isInline: true, dependencies: [{ kind: "component", type: i1.MatCheckbox, selector: "mat-checkbox", inputs: ["aria-label", "aria-labelledby", "aria-describedby", "id", "required", "labelPosition", "name", "value", "disableRipple", "tabIndex", "color", "disabledInteractive", "checked", "disabled", "indeterminate"], outputs: ["change", "indeterminateChange"], exportAs: ["matCheckbox"] }, { kind: "directive", type: i2.LegacyFormlyAttributes, selector: "[formlyAttributes]" }, { kind: "pipe", type: i3.AsyncPipe, name: "async" }, { kind: "pipe", type: i4.LegacyFormlySelectOptionsPipe, name: "formlySelectOptions" }], changeDetection: i0.ChangeDetectionStrategy.OnPush }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: FormlyFieldMultiCheckbox, decorators: [{ type: Component, args: [{ selector: 'formly-field-mat-multicheckbox', template: ` @for (option of props.options | formlySelectOptions: field | async; track $index; let i = $index) { <mat-checkbox [id]="id + '_' + i" [formlyAttributes]="field" [tabIndex]="props.tabindex" [color]="props.color" [labelPosition]="props.labelPosition" [checked]="isChecked(option)" [disabled]="formControl.disabled || option.disabled" (change)="onChange(option.value, $event.checked)" > {{ option.label }} </mat-checkbox> } `, changeDetection: ChangeDetectionStrategy.OnPush, host: { '[id]': 'id', }, }] }], propDecorators: { checkboxes: [{ type: ViewChildren, args: [MatCheckbox] }] } }); function withFormlyFieldMultiCheckbox() { return { types: [ { name: 'multicheckbox', component: FormlyFieldMultiCheckbox, wrappers: ['form-field'], }, ], }; } class FormlyMatMultiCheckboxModule { static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: FormlyMatMultiCheckboxModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); } static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "18.2.13", ngImport: i0, type: FormlyMatMultiCheckboxModule, declarations: [FormlyFieldMultiCheckbox], imports: [CommonModule, ReactiveFormsModule, MatCheckboxModule, FormlyMatFormFieldModule, FormlySelectModule, i2.FormlyModule] }); } static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: FormlyMatMultiCheckboxModule, imports: [CommonModule, ReactiveFormsModule, MatCheckboxModule, FormlyMatFormFieldModule, FormlySelectModule, FormlyModule.forChild(withFormlyFieldMultiCheckbox())] }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: FormlyMatMultiCheckboxModule, decorators: [{ type: NgModule, args: [{ declarations: [FormlyFieldMultiCheckbox], imports: [ CommonModule, ReactiveFormsModule, MatCheckboxModule, FormlyMatFormFieldModule, FormlySelectModule, FormlyModule.forChild(withFormlyFieldMultiCheckbox()), ], }] }] }); /** * Generated bundle index. Do not edit. */ export { FormlyFieldMultiCheckbox, FormlyMatMultiCheckboxModule, withFormlyFieldMultiCheckbox }; //# sourceMappingURL=ngx-formly-material-multicheckbox.mjs.map