You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
85 lines
2.2 KiB
85 lines
2.2 KiB
import { VerticalLayout, shortcut, Widget, map, some, each } from "@/core"; |
|
import { FormField } from "./form.field"; |
|
import { ButtonGroup } from "@/base"; |
|
|
|
@shortcut() |
|
export class Form extends Widget { |
|
static xtype = "bi.custom_form"; |
|
|
|
props = { |
|
baseCls: "bi-form", |
|
labelAlign: "right", |
|
layout: { type: VerticalLayout.xtype, 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: FormField.xtype, |
|
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()); |
|
} |
|
}
|
|
|