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. 77
      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_STOP = "EVENT_STOP";
BI.SearchTextValueTrigger.EVENT_START = "EVENT_START"; BI.SearchTextValueTrigger.EVENT_START = "EVENT_START";
BI.SearchTextValueTrigger.EVENT_CHANGE = "EVENT_CHANGE"; BI.SearchTextValueTrigger.EVENT_CHANGE = "EVENT_CHANGE";
BI.SearchTextValueTrigger.EVENT_CLEAR = "EVENT_CLEAR";
BI.shortcut("bi.search_text_value_trigger", BI.SearchTextValueTrigger); 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, chooseType: BI.ButtonGroup.CHOOSE_TYPE_SINGLE,
text: "", text: "",
value: "", value: "",
allowClear: false,
}); });
}, },
@ -33,7 +34,16 @@ BI.TextValueCombo = BI.inherit(BI.Widget, {
height: o.height, height: o.height,
text: o.text, text: o.text,
value: o.value, 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({ this.popup = BI.createWidget({
type: "bi.text_value_combo_popup", type: "bi.text_value_combo_popup",
@ -62,13 +72,18 @@ BI.TextValueCombo = BI.inherit(BI.Widget, {
minHeight: 25 minHeight: 25
} }
}); });
if(BI.isKey(o.value)) { if (BI.isKey(o.value)) {
this._checkError(o.value); this._checkError(o.value);
} }
}, },
_clear: function () {
this.trigger.attr("text", "");
this.setValue();
},
_checkError: function (v) { _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.trigger.options.tipType = "success";
this.element.removeClass("combo-error"); this.element.removeClass("combo-error");
} else { } else {

77
src/case/trigger/trigger.text.js

@ -7,25 +7,27 @@
*/ */
BI.TextTrigger = BI.inherit(BI.Trigger, { BI.TextTrigger = BI.inherit(BI.Trigger, {
_defaultConfig: function () { props: function () {
var self = this; var self = this;
var conf = BI.TextTrigger.superclass._defaultConfig.apply(this, arguments); return {
return BI.extend(conf, { baseCls: "bi-text-trigger",
baseCls: (conf.baseCls || "") + " bi-text-trigger",
height: 24, height: 24,
textHgap: 6, textHgap: 6,
textCls: "", textCls: "",
allowClear: false,
title: function () { title: function () {
return self.text.getText(); return self.text.getText();
} }
}); };
}, },
_init: function () { render: function () {
BI.TextTrigger.superclass._init.apply(this, arguments);
var self = this, o = this.options, c = this._const; var self = this, o = this.options, c = this._const;
this.text = BI.createWidget({ var text = {
type: "bi.label", type: "bi.label",
ref: function (_ref) {
self.text = _ref;
},
cls: "select-text-label" + (BI.isKey(o.textCls) ? (" " + o.textCls) : ""), cls: "select-text-label" + (BI.isKey(o.textCls) ? (" " + o.textCls) : ""),
textAlign: "left", textAlign: "left",
height: o.height, height: o.height,
@ -39,32 +41,69 @@ BI.TextTrigger = BI.inherit(BI.Trigger, {
tgap: o.textTgap, tgap: o.textTgap,
bgap: o.textBgap, bgap: o.textBgap,
readonly: o.readonly readonly: o.readonly
}); };
this.trigerButton = BI.createWidget({
var triggerButton = {
type: "bi.trigger_icon_button", type: "bi.trigger_icon_button",
ref: function (_ref) {
self.triggerButton = _ref;
},
width: o.triggerWidth || o.height width: o.triggerWidth || o.height
}); };
BI.createWidget({ return ({
element: this,
type: "bi.horizontal_fill", type: "bi.horizontal_fill",
items: [ items: [
{ {
el: this.text, el: text,
width: "fill" width: "fill"
}, { }, {
el: this.trigerButton, type: "bi.vertical_adapt",
width: o.triggerWidth || o.height 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
}
]
} }
] ]
}); });
}, },
getTextor: function() { 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 () {
return this.text; return this.text;
}, },
setTextCls: function(cls) { setTextCls: function (cls) {
var o = this.options; var o = this.options;
var oldCls = o.textCls; var oldCls = o.textCls;
o.textCls = cls; o.textCls = cls;
@ -80,4 +119,6 @@ BI.TextTrigger = BI.inherit(BI.Trigger, {
this.options.tipType = v; this.options.tipType = v;
} }
}); });
BI.TextTrigger.EVENT_CLEAR = "EVENT_CLEAR";
BI.shortcut("bi.text_trigger", BI.TextTrigger); 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), { return BI.extend(BI.SelectTextTrigger.superclass._defaultConfig.apply(this, arguments), {
baseCls: "bi-select-text-trigger", baseCls: "bi-select-text-trigger",
height: 24, height: 24,
allowClear: false,
}); });
}, },
@ -32,11 +33,20 @@ BI.SelectTextTrigger = BI.inherit(BI.Trigger, {
textTgap: o.textTgap, textTgap: o.textTgap,
textBgap: o.textBgap, textBgap: o.textBgap,
tipType: o.tipType, 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; var o = this.options;
vals = BI.isArray(vals) ? vals : [vals]; vals = BI.isArray(vals) ? vals : [vals];
var result = []; var result = [];
@ -51,12 +61,12 @@ BI.SelectTextTrigger = BI.inherit(BI.Trigger, {
return { return {
textCls: "", textCls: "",
text: result.join(",") text: result.join(",")
} };
} else { } else {
return { return {
textCls: "bi-water-mark", textCls: "bi-water-mark",
text: BI.isFunction(o.text) ? o.text() : o.text text: BI.isFunction(o.text) ? o.text() : o.text
} };
} }
}, },
@ -70,7 +80,7 @@ BI.SelectTextTrigger = BI.inherit(BI.Trigger, {
this.trigger.setTipType(v); this.trigger.setTipType(v);
}, },
getTextor: function() { getTextor: function () {
return this.trigger.getTextor(); return this.trigger.getTextor();
}, },
@ -78,4 +88,6 @@ BI.SelectTextTrigger = BI.inherit(BI.Trigger, {
this.options.items = items; this.options.items = items;
} }
}); });
BI.SelectTextTrigger.EVENT_CLEAR = "EVENT_CLEAR";
BI.shortcut("bi.select_text_trigger", BI.SelectTextTrigger); BI.shortcut("bi.select_text_trigger", BI.SelectTextTrigger);

Loading…
Cancel
Save