dijit filteringSelect with min length

随声附和 提交于 2019-12-22 08:18:43

问题


I can't seem to find a way to require the filtering select input to be of a certain length. I've tried like this:

new dijit.form.FilteringSelect({
    'name': 'bla',
    'store': jsonRestStore,
    'searchAttr': "name",
    'pattern': '.{3,}',
    'regExp': '.{3,}'
});

but it doesn't change a thing. I want the filtering select to only query the store, if at least 3 characters have been entered. Can't be that exotic a requirement, can it? There are thousands of items behind that store, so querying that with just 1 or 2 characters is slow.


回答1:


I did a bit more searching and found this post on the dojo mailing list. To summarize, there is no way to native support in the FilteringSelect for it, but it is extremely easy to implement.

// custom min input character count to trigger search
minKeyCount: 3,

// override search method, count the input length
_startSearch: function (/*String*/key) {
    if (!key || key.length < this.minKeyCount) {
    this.closeDropDown();
    return;
    }
    this.inherited(arguments);
}

Also in the API Docs, there is a searchDelay attribute, which could be helpful in minimizes the number of queries.

searchDelay 
Delay in milliseconds between when user types something and we start searching based on that value


来源:https://stackoverflow.com/questions/15949425/dijit-filteringselect-with-min-length

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!