import { AbstractControl } from '@angular/forms'; import { Component, Input, OnInit } from '@angular/core'; import { hasOwn } from '../../shared/utility.functions'; import { JsonSchemaFormService } from '../../json-schema-form.service'; @Component({ // tslint:disable-next-line:component-selector selector: 'material-button-widget', template: `
`, styles: [` button { margin-top: 10px; } `], }) export class MaterialButtonComponent implements OnInit { formControl: AbstractControl; controlName: string; controlValue: any; controlDisabled = false; boundControl = false; options: any; @Input() layoutNode: any; @Input() layoutIndex: number[]; @Input() dataIndex: number[]; constructor( private jsf: JsonSchemaFormService ) { } ngOnInit() { this.options = this.layoutNode.options || {}; this.jsf.initializeControl(this); if (hasOwn(this.options, 'disabled')) { this.controlDisabled = this.options.disabled; } else if (this.jsf.formOptions.disableInvalidSubmit) { this.controlDisabled = !this.jsf.isValid; this.jsf.isValidChanges.subscribe(isValid => this.controlDisabled = !isValid); } } updateValue(event) { if (typeof this.options.onClick === 'function') { this.options.onClick(event); } else { this.jsf.updateValue(this, event.target.value); } } }