有组合框和关联的商店,如果商店中没有用户输入的值的条目,则重置一切都是正确的,但如果用户输入商店中的值但他会这样做,则有一个令人不快的功能当存储还没有来得及加载输入值时,它很快就会被重置。
如果用户没有等到商店加载(如果输入的值在商店中),则当用户移动到另一个表单字段时如何不重置用户输入的值
var bik = new Ext.form.ComboBox({
store: storeBik,
displayField: 'BANK_NAME',
fieldLabel: 'БИК',
name: 'BIK',
hiddenName: 'BIK',
valueField:'BIK',
typeAhead: true,
forceSelection:true,
selectOnFocus:true,
triggerAction: 'all',
minChars : 1,
mode: 'remote'
resizable : true,
validator : validBik,
tpl: new Ext.XTemplate('<tpl for="."><div class="x-combo-list-item"><b>{BIK} </b> {BANK}</div></tpl>')
});
最佳答案
发生这种情况的原因是您开启了forceSelection
。模糊后,ComboBox
尝试在存储中为键入的值查找合适的记录。如果此类记录不存在,则会重置值。
我可以想出两种解决方案:
- 关闭
forceSelection
- 扩展
组合框
我看到您附加了 validBik
验证器。如果您可以在客户端验证值,则关闭 forceSelection
即可获得所需的一切。另一方面,如果您确实需要存储数据以从中选择值,那么您应该扩展 ComboBox
。
下面是 ComboBox
修改,它在请求结束之前保留值。它并不完美,但也许会对您有所帮助:
var bik = new Ext.form.ComboBox({
[...],
// Check if query is queued or in progress
isLoading: function() {
return this.isStoreLoading || // check if store is making ajax request
this.isQueryPending; // check if there is any query pending
},
// This is responsible for finding matching record in store
assertValue: function() {
if (this.isLoading()) {
this.assertionRequired = true;
return;
}
Ext.form.ComboBox.prototype.assertValue.apply(this, arguments);
},
// this is private method; you can equally write 'beforeload' event handler for store
onBeforeLoad: function(){
this.isQueryPending = false;
this.isStoreLoading = true;
Ext.form.ComboBox.prototype.onBeforeLoad.apply(this, arguments);
},
// catch moment when query is added to queue
onKeyUp: function(e){
var k = e.getKey();
if(this.editable !== false && this.readOnly !== true && (k == e.BACKSPACE || !e.isSpecialKey())){
this.isQueryPending = true;
}
Ext.form.ComboBox.prototype.onKeyUp.apply(this, arguments);
},
// this is private method; you can equally write 'load' event handler for store
onLoad: function() {
Ext.form.ComboBox.prototype.onLoad.apply(this, arguments);
this.isQueryPending = false;
this.isStoreLoading = false;
if (this.assertionRequired === true) {
delete this.assertionRequired;
this.assertValue();
}
}
});
关于javascript - 组合框 ExtJ 的不良行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19270921/