ExtJS findExact()和自定义验证器错误 [英] ExtJS findExact() and custom validator bug
问题描述
我在我的组合框中使用自定义验证器:
I'm using a custom validator on my combobox's:
function(v) {
console.log(v === 'some value I know for SURE is in the store'); // (1)
var index = this.getStore().findExact(this.displayField, v);
return (index!==-1) ? true : 'Invalid selection';
}
基本上承认与 forceSelection 但允许用户键入任意文本以尝试自动完成。
Basically admits the same set as forceSelection but allows the user to type arbitrary text to attempt to auto-complete.
但是;我有非常奇怪的结果与 findExact()
。例如,如果组合框的值当前有效,并且用户执行空格+退格,验证器将失败,即使输出of(1) true 。
However; I'm having really odd results with findExact()
. For example, if the combobox's value is currently valid, and a user does a space + backspace, the validator will fail, even though the output of (1) is true.
任何想法是什么原因导致的问题?
Any ideas what is causing the problem? The end-experience is currently very buggy-feeling..
推荐答案
当你键入额外的空间时,存储被过滤。
When you type additional space, store is filtered. After you press backspace, and validator is fired, store is still empty.
如果您有本地存储,那么您可以在每次更改后进行一些延迟验证组合。示例:
If you have local store, then you could validate combo with some delay after each change. Example:
listeners: {
change: function() {
this.validate();
},
delay: 100
}
另一方面,如果您有远程商店,请尝试这样:
On the other hand if you have remote store, try something like this:
validator: function(v) {
var store = this.getStore(),
index = store.findExact(this.displayField, v);
if (index === -1 && store.isLoading()) {
store.on('load', function() {
this.validate();
}, this, { single: true, delay: 100 });
}
return (index !== -1) ? true : 'Invalid selection';
}
这篇关于ExtJS findExact()和自定义验证器错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!