Browse Source

无JIRA feat:单选下拉框支持清除

clear既清空value,也清空text
es6
zsmj 3 years ago
parent
commit
2e1322acf1
  1. 1
      src/case/combo/searchtextvaluecombo/trigger.searchtextvalue.js
  2. 21
      src/case/combo/textvaluecombo/combo.textvalue.js
  3. 75
      src/case/trigger/trigger.text.js
  4. 22
      src/case/trigger/trigger.text.select.js

1
src/case/combo/searchtextvaluecombo/trigger.searchtextvalue.js

@ -111,4 +111,5 @@ BI.SearchTextValueTrigger.EVENT_SEARCHING = "EVENT_SEARCHING";
BI.SearchTextValueTrigger.EVENT_STOP = "EVENT_STOP";
BI.SearchTextValueTrigger.EVENT_START = "EVENT_START";
BI.SearchTextValueTrigger.EVENT_CHANGE = "EVENT_CHANGE";
BI.SearchTextValueTrigger.EVENT_CLEAR = "EVENT_CLEAR";
BI.shortcut("bi.search_text_value_trigger", BI.SearchTextValueTrigger);

21
src/case/combo/textvaluecombo/combo.textvalue.js

@ -12,6 +12,7 @@ BI.TextValueCombo = BI.inherit(BI.Widget, {
chooseType: BI.ButtonGroup.CHOOSE_TYPE_SINGLE,
text: "",
value: "",
allowClear: false,
});
},
@ -33,7 +34,16 @@ BI.TextValueCombo = BI.inherit(BI.Widget, {
height: o.height,
text: o.text,
value: o.value,
warningTitle: o.warningTitle
warningTitle: o.warningTitle,
allowClear: o.allowClear,
listeners: [
{
eventName: BI.SelectTextTrigger.EVENT_CLEAR,
action: function () {
self._clear();
}
}
],
});
this.popup = BI.createWidget({
type: "bi.text_value_combo_popup",
@ -62,13 +72,18 @@ BI.TextValueCombo = BI.inherit(BI.Widget, {
minHeight: 25
}
});
if(BI.isKey(o.value)) {
if (BI.isKey(o.value)) {
this._checkError(o.value);
}
},
_clear: function () {
this.trigger.attr("text", "");
this.setValue();
},
_checkError: function (v) {
if(BI.isNull(v) || BI.isEmptyArray(v) || BI.isEmptyString(v)) {
if (BI.isNull(v) || BI.isEmptyArray(v) || BI.isEmptyString(v)) {
this.trigger.options.tipType = "success";
this.element.removeClass("combo-error");
} else {

75
src/case/trigger/trigger.text.js

@ -7,25 +7,27 @@
*/
BI.TextTrigger = BI.inherit(BI.Trigger, {
_defaultConfig: function () {
props: function () {
var self = this;
var conf = BI.TextTrigger.superclass._defaultConfig.apply(this, arguments);
return BI.extend(conf, {
baseCls: (conf.baseCls || "") + " bi-text-trigger",
return {
baseCls: "bi-text-trigger",
height: 24,
textHgap: 6,
textCls: "",
allowClear: false,
title: function () {
return self.text.getText();
}
});
};
},
_init: function () {
BI.TextTrigger.superclass._init.apply(this, arguments);
render: function () {
var self = this, o = this.options, c = this._const;
this.text = BI.createWidget({
var text = {
type: "bi.label",
ref: function (_ref) {
self.text = _ref;
},
cls: "select-text-label" + (BI.isKey(o.textCls) ? (" " + o.textCls) : ""),
textAlign: "left",
height: o.height,
@ -39,32 +41,69 @@ BI.TextTrigger = BI.inherit(BI.Trigger, {
tgap: o.textTgap,
bgap: o.textBgap,
readonly: o.readonly
});
this.trigerButton = BI.createWidget({
};
var triggerButton = {
type: "bi.trigger_icon_button",
ref: function (_ref) {
self.triggerButton = _ref;
},
width: o.triggerWidth || o.height
});
};
BI.createWidget({
element: this,
return ({
type: "bi.horizontal_fill",
items: [
{
el: this.text,
el: text,
width: "fill"
}, {
el: this.trigerButton,
type: "bi.vertical_adapt",
horizontalAlign: "left",
width: o.triggerWidth || o.height,
scrollable: false,
items: [
{
el: {
type: "bi.icon_button",
ref: function (_ref) {
self.clearBtn = _ref;
},
cls: "close-h-font",
stopPropagation: true,
handler: function () {
self.fireEvent(BI.TextTrigger.EVENT_CLEAR);
self.clearBtn.setVisible(false);
},
invisible: true,
},
width: o.triggerWidth || o.height
}, {
el: triggerButton,
width: o.triggerWidth || o.height
}
]
}
]
});
},
mounted: function () {
var self = this;
if (this.options.allowClear) {
this.element.hover(function () {
BI.isKey(self.text.getText()) && self.clearBtn.setVisible(true);
}, function () {
self.clearBtn.setVisible(false);
});
}
},
getTextor: function() {
getTextor: function () {
return this.text;
},
setTextCls: function(cls) {
setTextCls: function (cls) {
var o = this.options;
var oldCls = o.textCls;
o.textCls = cls;
@ -80,4 +119,6 @@ BI.TextTrigger = BI.inherit(BI.Trigger, {
this.options.tipType = v;
}
});
BI.TextTrigger.EVENT_CLEAR = "EVENT_CLEAR";
BI.shortcut("bi.text_trigger", BI.TextTrigger);

22
src/case/trigger/trigger.text.select.js

@ -11,6 +11,7 @@ BI.SelectTextTrigger = BI.inherit(BI.Trigger, {
return BI.extend(BI.SelectTextTrigger.superclass._defaultConfig.apply(this, arguments), {
baseCls: "bi-select-text-trigger",
height: 24,
allowClear: false,
});
},
@ -32,11 +33,20 @@ BI.SelectTextTrigger = BI.inherit(BI.Trigger, {
textTgap: o.textTgap,
textBgap: o.textBgap,
tipType: o.tipType,
warningTitle: o.warningTitle
warningTitle: o.warningTitle,
allowClear: o.allowClear,
listeners: [
{
eventName: BI.TextTrigger.EVENT_CLEAR,
action: function () {
self.fireEvent(BI.SelectTextTrigger.EVENT_CLEAR);
}
}
]
});
},
_digest: function(vals, items){
_digest: function (vals, items) {
var o = this.options;
vals = BI.isArray(vals) ? vals : [vals];
var result = [];
@ -51,12 +61,12 @@ BI.SelectTextTrigger = BI.inherit(BI.Trigger, {
return {
textCls: "",
text: result.join(",")
}
};
} else {
return {
textCls: "bi-water-mark",
text: BI.isFunction(o.text) ? o.text() : o.text
}
};
}
},
@ -70,7 +80,7 @@ BI.SelectTextTrigger = BI.inherit(BI.Trigger, {
this.trigger.setTipType(v);
},
getTextor: function() {
getTextor: function () {
return this.trigger.getTextor();
},
@ -78,4 +88,6 @@ BI.SelectTextTrigger = BI.inherit(BI.Trigger, {
this.options.items = items;
}
});
BI.SelectTextTrigger.EVENT_CLEAR = "EVENT_CLEAR";
BI.shortcut("bi.select_text_trigger", BI.SelectTextTrigger);

Loading…
Cancel
Save