组合框 ExtJs 的不需要的行为
unwanted behavior of combo box ExtJs
有组合框和关联的商店,如果存储中没有用户输入的值的条目,则重置一切是正确的,但是如果用户输入一个值,则有一个令人不快的功能在商店,但他会在存储没有时间加载时快速完成,输入值将被重置。
如果用户没有等到存储加载(如果输入的值在存储中(,则当用户移动到另一个表单字段时,如何不重置用户输入的值
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
尝试在存储中为键入的值找到合适的记录。如果此类记录不存在,则会重置值。
我可以想到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();
}
}
});
相关文章:
- 如何在不需要单击按钮的情况下获取选项的值
- Javascript不需要的关闭行为
- 删除客户端浏览器上不需要的内容
- 不允许在字段中输入不需要的字符
- 不需要的JSON响应
- 如何使图像适合TD,而不需要包装在不同的屏幕分辨率上
- 使用一个Javascript函数提交多个表单可以在FF中工作,而不需要其他浏览器
- jQuery自动完成显示不需要的动态html标记
- 在Knockout js中创建一个包含多行的表,而不需要推送
- AngularJs正在解码HTML字符(不需要)
- jQuery regex从文本链接-添加不需要的域到链接
- 防止从浏览器到应用商店的不需要的重定向
- 外部解析RSS提要,不需要像谷歌和服务器端那样的任何库
- 不需要的异步事件调度
- 是否有任何不需要后端的验证码角度指令
- Ajax 请求给出不需要的响应
- Jquery/javascript:加载页面时不需要的重复函数
- 为什么Java代码需要编译,而JavaScript代码不需要
- Angular SPA中不需要的页面刷新
- 组合框 ExtJs 的不需要的行为