angular2-json-schema-form
Version:
Angular 2 JSON Schema Form builder
65 lines (59 loc) • 2.13 kB
text/typescript
import { Component, Input, OnInit } from '@angular/core';
import { AbstractControl } from '@angular/forms';
import { JsonSchemaFormService } from '../library/json-schema-form.service';
@Component({
selector: 'input-widget',
template: `
<div
[]="options?.htmlClass">
<label *ngIf="options?.title"
[]="'control' + layoutNode?._id"
[]="options?.labelHtmlClass"
[]="options?.notitle"
[]="options?.title"></label>
<input
[]="'control' + layoutNode?._id + 'Status'"
[]="'control' + layoutNode?._id + 'Autocomplete'"
[]="options?.maxLength"
[]="options?.minLength"
[]="options?.pattern"
[]="options?.placeholder"
[]="options?.required"
[]="options?.fieldHtmlClass"
[]="controlDisabled"
[]="'control' + layoutNode?._id"
[]="controlName"
[]="options?.readonly ? 'readonly' : null"
[]="layoutNode?.type"
[]="controlValue"
(input)="updateValue($event)">
<datalist *ngIf="options?.typeahead?.source"
[]="'control' + layoutNode?._id + 'Autocomplete'">
<option *ngFor="let word of options?.typeahead?.source"
[]="word">
</datalist>
</div>`,
})
export class InputComponent implements OnInit {
private formControl: AbstractControl;
private controlName: string;
private controlValue: any;
private controlDisabled: boolean = false;
private boundControl: boolean = false;
private options: any;
private autoCompleteList: string[] = [];
@Input() formID: number;
@Input() layoutNode: any;
@Input() layoutIndex: number[];
@Input() dataIndex: number[];
constructor(
private jsf: JsonSchemaFormService
) { }
ngOnInit() {
this.options = this.layoutNode.options;
this.jsf.initializeControl(this);
}
private updateValue(event) {
this.jsf.updateValue(this, event.target.value);
}
}