import { AbstractControl } from '@angular/forms'; import { buildTitleMap } 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-radios-widget', template: `
`, styles: [` mat-radio-group { display: inline-flex; } mat-radio-button { margin: 2px; } mat-error { font-size: 75%; } `] }) export class MaterialRadiosComponent implements OnInit { formControl: AbstractControl; controlName: string; controlValue: any; controlDisabled = false; boundControl = false; options: any; flexDirection = 'column'; radiosList: any[] = []; @Input() layoutNode: any; @Input() layoutIndex: number[]; @Input() dataIndex: number[]; constructor( private jsf: JsonSchemaFormService ) { } ngOnInit() { this.options = this.layoutNode.options || {}; if (this.layoutNode.type === 'radios-inline') { this.flexDirection = 'row'; } this.radiosList = buildTitleMap( this.options.titleMap || this.options.enumNames, this.options.enum, true ); this.jsf.initializeControl(this, !this.options.readonly); } updateValue(value) { this.options.showErrors = true; this.jsf.updateValue(this, value); } }