问题
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.
- User selects 1 value of FilteringSelect.
- This value set as value of FilteringSelect.
- But after user decides to change this value on empty value.
- As I understand, because required:false FilteringSelect should allow
to set empty value, but it is not. I observe this behavior here:
- User clicks FilteringSelect textbox
- User clears it
- 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