You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

142 lines
4.0 KiB
JavaScript

12 months ago
function TCombo(id, url, isOnChange, isBlur, isAfter, isOnKeyPressed, hiddenId) {
var self = this;
var comboObj;
var url;
this.url = url;
this.id = id;//orig id name
var isOnChange;
this.isOnChange = isOnChange;
var hiddenId;
this.hiddenId = hiddenId;
this.isBlur = isBlur;
this.isOnKeyPressed = isOnKeyPressed
this.isOnSelectionChange = false;
this.isAfter = isAfter;
this.isOnOpen = false;
var blurType = 0;
this.blurType = blurType;
this.isLinkAnother = false;//是否关联其他combo信息联动
var stringObj = String;
this.initComboEvent = function(){
self.comboObj = dhtmlXComboFromSelect(self.id);
};
this.setRequestUrl = function(url){
self.url = url;
};
this.bind = function(){
if(isAfter){
self.comboObj.loadXML(self.url,self.afterFun);
}else{
self.comboObj.loadXML(self.url);
}
if(isOnChange){
self.comboObj.attachEvent("onChange",self.onChangeFun);
}
if(isBlur){
self.comboObj.attachEvent("onBlur",self.blurFun);
}
if(isOnKeyPressed){
self.comboObj.attachEvent("onKeyPressed",self.onKeyPressedFun);
}
};
this.afterFun = function(){
};
this.onChangeFun = function(){
self.setText(self.getObjValue(self.hiddenId));
};
this.blurFun = function(){
self.blurSplitFun();
};
this.onOpenFun = function(){
};
this.setText = function(val){
self.comboObj.setComboText(val);
};
this.blurSplitFun = function(){
var splitCount = self.comboObj.getComboText().trim().indexOf("|");
if(self.comboObj.getComboText().trim() == "")
{
self.setObjValue(self.hiddenId,"");
self.comboObj.setComboText(self.getObjValue(self.hiddenId));
}
else
{
if(splitCount > 0){
splitCount += 2;
}
var selectedStr = self.comboObj.getComboText().trim().substring(splitCount);
if(splitCount > 0){
self.comboObj.setComboText(selectedStr);
self.setObjValue(self.hiddenId,selectedStr);
}else{
self.comboObj.setComboText(self.getObjValue(self.hiddenId));
}
}
};
this.onKeyPressedFun = function(keyCode){
if(keyCode!="8"){
var arrayArg = new Array();
setTimeout(function(){
var filterCount = 0;
var is = -1;
var ishd = self.getObjValue(self.hiddenId);
if("" != self.comboObj.getComboText().trim()){
while("undefined" != typeof self.comboObj.getOptionByIndex(filterCount)){
var comboValue = self.comboObj.getOptionByIndex(filterCount).text.toUpperCase();
var enterValue = self.comboObj.getComboText().trim().toUpperCase();
self.setObjValue(self.hiddenId,self.comboObj.getComboText().trim().toUpperCase());
if(comboValue.indexOf(enterValue) == 0){
self.comboObj.selectOption(filterCount,true,true);
is = filterCount;
break;
}
++filterCount;
}
if(is==-1){
self.setObjValue(self.hiddenId,ishd);
}
}
},10);
}
};
this.getObj = function(id){
return document.getElementById(id);
};
this.setObjValue = function(id,val){
self.getObj(id).value = val;
};
this.getObjValue = function(id){
return self.getObj(id).value;
};
}
String.prototype.trim = function() { return this.replace(/(^\s*)|(\s*$)/g,""); }