forked from fanruan/fineui
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.
90 lines
2.1 KiB
90 lines
2.1 KiB
3 years ago
|
/**
|
||
|
* @author windy
|
||
|
* @version 2.0
|
||
|
* Created by windy on 2022/1/11
|
||
|
*/
|
||
|
BI.Form = BI.inherit(BI.Widget, {
|
||
|
|
||
|
props: {
|
||
|
baseCls: "bi-form",
|
||
|
layout: {
|
||
|
type: "bi.vertical",
|
||
|
vgap: 20
|
||
|
},
|
||
|
items: [{
|
||
|
validate: BI.emptyFn,
|
||
|
tip: BI.emptyFn,
|
||
|
label: "",
|
||
|
el: {}
|
||
|
}],
|
||
|
labelWidth: ""
|
||
|
},
|
||
|
|
||
|
render: function () {
|
||
|
var self = this, o = this.options;
|
||
|
|
||
|
return {
|
||
|
type: "bi.button_group",
|
||
|
items: this._createItems(),
|
||
|
layouts: [o.layout],
|
||
|
ref: function (ref) {
|
||
|
self.group = ref;
|
||
|
}
|
||
|
};
|
||
|
},
|
||
|
|
||
|
_createItems: function () {
|
||
|
var o = this.options;
|
||
|
|
||
|
return BI.map(o.items, function (idx, item) {
|
||
|
return {
|
||
|
type: "bi.form_field",
|
||
|
height: item.el.height || 28,
|
||
|
labelWidth: o.labelWidth,
|
||
|
el: item.el,
|
||
|
label: item.label,
|
||
|
tip: item.tip,
|
||
|
validate: item.validate,
|
||
|
listeners: [{
|
||
|
eventName: "EVENT_CHANGE",
|
||
|
action: function () {
|
||
|
this.validate();
|
||
|
}
|
||
|
}]
|
||
|
};
|
||
|
});
|
||
|
},
|
||
|
|
||
|
isAllValid: function () {
|
||
|
return !BI.some(this.validateWithNoTip(), function (idx, v) {
|
||
|
return !v;
|
||
|
});
|
||
|
},
|
||
|
|
||
|
validateWithNoTip: function () {
|
||
|
var validInfo = [];
|
||
|
BI.each(this.group.getAllButtons(), function (idx, button) {
|
||
|
validInfo.push(button.validateWithNoTip());
|
||
|
});
|
||
|
|
||
|
return validInfo;
|
||
|
},
|
||
|
|
||
|
validate: function () {
|
||
|
var validInfo = [];
|
||
|
BI.each(this.group.getAllButtons(), function (idx, button) {
|
||
|
validInfo.push(button.validate());
|
||
|
});
|
||
|
|
||
|
return validInfo;
|
||
|
},
|
||
|
|
||
|
getValue: function () {
|
||
|
return !this.isAllValid() ? null : BI.map(this.group.getAllButtons(), function (idx, button) {
|
||
|
return button.getValue();
|
||
|
});
|
||
|
}
|
||
|
});
|
||
|
|
||
|
BI.shortcut("bi.custom_form", BI.Form);
|