有组合框和关联的商店,如果用户输入的值中存储条目没有重置一切都是正确的,但如果用户输入的是Store的值,他会做一个不愉快的功能它很快就会在存储没有时间加载输入值时重置。
如果用户没有等到存储加载(如果输入的值在Store中),那么如果用户移动到另一个表单字段时输入的值不重置
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>')
});
答案 0 :(得分:1)
发生这种情况的原因是因为您已启用forceSelection
。模糊ComboBox
试图在商店中找到类型值的合适记录。如果这样的记录不存在,则重置值。
我可以考虑2个解决方案:
forceSelection
ComboBox
我看到您附加了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();
}
}
});