import { AbstractControl } from '@angular/forms';
import { buildTitleMap, isArray } from '../../shared';
import { Component, Input, OnInit } from '@angular/core';
import { JsonSchemaFormService } from '../../json-schema-form.service';
@Component({
// tslint:disable-next-line:component-selector
selector: 'material-select-widget',
template: `
`,
styles: [`
mat-error { font-size: 75%; margin-top: -1rem; margin-bottom: 0.5rem; }
::ng-deep json-schema-form mat-form-field .mat-form-field-wrapper .mat-form-field-flex
.mat-form-field-infix { width: initial; }
`],
})
export class MaterialSelectComponent implements OnInit {
formControl: AbstractControl;
controlName: string;
controlValue: any;
controlDisabled = false;
boundControl = false;
options: any;
selectList: any[] = [];
isArray = isArray;
@Input() layoutNode: any;
@Input() layoutIndex: number[];
@Input() dataIndex: number[];
constructor(
private jsf: JsonSchemaFormService
) { }
ngOnInit() {
this.options = this.layoutNode.options || {};
this.selectList = buildTitleMap(
this.options.titleMap || this.options.enumNames,
this.options.enum, !!this.options.required, !!this.options.flatList
);
this.jsf.initializeControl(this, !this.options.readonly);
if (!this.options.notitle && !this.options.description && this.options.placeholder) {
this.options.description = this.options.placeholder;
}
}
updateValue(event) {
this.options.showErrors = true;
this.jsf.updateValue(this, event.value);
}
}