有组合框和关联的Store,如果在Store中没有输入用户输入的值的条目,那么一切都是正确的,但是如果用户输入了一个值,即在Store,但是他会在存储没有时间加载输入值的情况下,输入值将被重置,那么就会有一个不愉快的特性。
当用户移动到另一个表单字段时,如何不重置用户输入的值,如果用户没有等到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>')
});发布于 2013-10-16 10:06:50
之所以会发生这种情况,是因为您打开了forceSelection。在模糊之后,ComboBox正在试图为类型化的值在存储中找到合适的记录。如果这种记录不存在,它会重置值。
我可以想出两种解决方案:
forceSelectionComboBox我看到您已经附加了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();
}
}
});https://stackoverflow.com/questions/19270921
复制相似问题