|
|
|
import { shortcut, Widget, map, some, each } from "@/core";
|
|
|
|
import { ButtonGroup } from "@/base";
|
|
|
|
|
|
|
|
@shortcut()
|
|
|
|
export class Form extends Widget {
|
|
|
|
static xtype = "bi.custom_form";
|
|
|
|
|
|
|
|
props = {
|
|
|
|
baseCls: "bi-form",
|
|
|
|
labelAlign: "right",
|
|
|
|
layout: { type: "bi.vertical", vgap: 20 },
|
|
|
|
items: [{ label: "", el: {} }],
|
|
|
|
labelWidth: "",
|
|
|
|
headerCls: "",
|
|
|
|
};
|
|
|
|
|
|
|
|
static EVENT_CHANGE = "EVENT_CHANGE";
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const o = this.options;
|
|
|
|
|
|
|
|
return {
|
|
|
|
type: ButtonGroup.xtype,
|
|
|
|
items: this._createItems(),
|
|
|
|
layouts: [o.layout],
|
|
|
|
ref: _ref => {
|
|
|
|
this.group = _ref;
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
_createItems() {
|
|
|
|
const self = this;
|
|
|
|
const o = this.options;
|
|
|
|
|
|
|
|
return map(o.items, (idx, item) => {
|
|
|
|
return {
|
|
|
|
type: "bi.form_field",
|
|
|
|
height: item.el.height || 28,
|
|
|
|
labelAlign: o.labelAlign,
|
|
|
|
labelWidth: o.labelWidth,
|
|
|
|
headerCls: o.headerCls,
|
|
|
|
el: item.el,
|
|
|
|
label: item.label,
|
|
|
|
tip: item.tip,
|
|
|
|
validate: item.validate,
|
|
|
|
listeners: [
|
|
|
|
{
|
|
|
|
eventName: "EVENT_CHANGE",
|
|
|
|
action () {
|
|
|
|
self.fireEvent(Form.EVENT_CHANGE, this.validate());
|
|
|
|
},
|
|
|
|
}
|
|
|
|
],
|
|
|
|
};
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
isAllValid() {
|
|
|
|
return !some(this.validateWithNoTip(), (idx, v) => !v);
|
|
|
|
}
|
|
|
|
|
|
|
|
validateWithNoTip() {
|
|
|
|
const validInfo = [];
|
|
|
|
each(this.group.getAllButtons(), (idx, button) => {
|
|
|
|
validInfo.push(button.validateWithNoTip());
|
|
|
|
});
|
|
|
|
|
|
|
|
return validInfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
validate() {
|
|
|
|
const validInfo = [];
|
|
|
|
each(this.group.getAllButtons(), (idx, button) => {
|
|
|
|
validInfo.push(button.validate());
|
|
|
|
});
|
|
|
|
|
|
|
|
return validInfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
getValue() {
|
|
|
|
return !this.isAllValid()
|
|
|
|
? null
|
|
|
|
: map(this.group.getAllButtons(), (idx, button) => button.getValue());
|
|
|
|
}
|
|
|
|
}
|