Dojo: Select of empty value for FilteringSelect while required=false

萝らか妹 提交于 2019-12-11 02:24:44

问题


Please look on this code:

dojo.require('dijit.form.FilteringSelect');
dojo.require('dojo.store.JsonRest');

dojo.declare('JsonFilteringSelect', dijit.form.FilteringSelect, {
    constructor: function (options) {
        dojo.declare.safeMixin(this, options);
        if (this.url) {
            this.store = new dojo.store.JsonRest({
                target: this.url
            });
        } else {
            console.log('JsonFilteringSelect: options.url is not defined');
        }
    }
});

var getPersonJsonFilteringSelect = new JsonFilteringSelect({
            url: '/person/get',
            name: 'Test',
            title: 'Test title',
            required: false,
            autoComplete:false,
            value: '',
            pageSize:10,
            queryExpr:'${0}'
        }, dojo.byId('select'));

getPersonJsonFilteringSelect.startup();
});

Use case: Suppose I have 20 results into my FilteringSelect.

  1. User selects 1 value of FilteringSelect.
  2. This value set as value of FilteringSelect.
  3. But after user decides to change this value on empty value.
  4. As I understand, because required:false FilteringSelect should allow to set empty value, but it is not. I observe this behavior here:
    1. User clicks FilteringSelect textbox
    2. User clears it
    3. While user presses "Tab" or clicks by other element - FilteringSelect automatically selects first value.

How could I allow user to set empty value into FilteringSelect?


回答1:


You should add an empty entry ("" or null maybe? I know "" works) to your data store after it's loaded (I'd put it at the beginning) but before startup of the widget.

The "required" issue is strange with FilteringSelect because it won't let you select any arbitrary value -- it has to be an entry from the data store. Yet, if it's not required shouldn't it not care?... Dojo is strange sometimes.



来源:https://stackoverflow.com/questions/20162572/dojo-select-of-empty-value-for-filteringselect-while-required-false

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