我在组合框上使用自定义验证器:
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相同的集合但允许用户键入任意文本以尝试自动完成。
但是;我用 findExact()
得到了非常奇怪的结果。例如,如果组合框的值当前为有效,并且用户执行了空格 + 退格,验证器将失败,即使输出(1) 是正确的。
任何想法是什么导致了这个问题?目前的最终体验是非常有故障的感觉..
最佳答案
当您键入额外的空间时,存储会被过滤。按退格键并触发验证程序后,存储仍然是空的。
如果您有本地商店,那么您可以在每次更改后延迟验证组合。示例:
listeners: {
change: function() {
this.validate();
},
delay: 100
}
这应该足够了。
另一方面,如果您有远程存储,请尝试这样的操作:
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() 和自定义验证器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19885503/