ohayolibs
Version:
Ohayo is a set of essential modules for ohayojp.
54 lines (46 loc) • 1.52 kB
text/typescript
import { Component, OnInit, ViewEncapsulation } from '@angular/core';
import { SafeHtml } from '@angular/platform-browser';
import { FormProperty } from '../../model/form.property';
import { ArrayLayoutWidget } from '../../widget';
export class ArrayWidget extends ArrayLayoutWidget implements OnInit {
addTitle: SafeHtml;
addType: string;
removeTitle: string | null;
arraySpan = 8;
get addDisabled(): boolean {
return (
this.disabled || (this.schema.maxItems != null && (this.formProperty.properties as FormProperty[]).length >= this.schema.maxItems!)
);
}
get showRemove(): boolean {
return !this.disabled && !!this.removeTitle;
}
ngOnInit(): void {
const { grid, addTitle, addType, removable, removeTitle } = this.ui;
if (grid && grid.arraySpan) {
this.arraySpan = grid.arraySpan;
}
this.addTitle = this.dom.bypassSecurityTrustHtml(addTitle || this.l.addText);
this.addType = addType || 'dashed';
this.removeTitle = removable === false ? null : removeTitle || this.l.removeText;
}
addItem(): void {
const property = this.formProperty.add({});
if (this.ui.add) {
this.ui.add(property);
}
}
removeItem(index: number): void {
this.formProperty.remove(index);
if (this.ui.remove) {
this.ui.remove(index);
}
}
}