问题描述
请看这个代码:
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();
});
用例:假设我的FilteringSelect中有20个结果。
Use case: Suppose I have 20 results into my FilteringSelect.
- 用户选择1个FilteringSelect的值。
- 此值设置为
FilteringSelect。 - 但用户决定在
空值上更改此值。 - 据了解,因为必需:false FilteringSelect应允许
设置空值,但不是。我在这里观察到这个行为:
- User selects 1 value of FilteringSelect.
- This value set as value ofFilteringSelect.
- But after user decides to change this value on empty value.
- As I understand, because required:false FilteringSelect should allowto set empty value, but it is not. I observe this behavior here:
- 用户点击FilteringSelect文本框
- 用户清除
- 用户按Tab或其他元素点击 - FilteringSelect自动选择第一个值。
- User clicks FilteringSelect textbox
- User clears it
- While user presses "Tab" or clicks by other element - FilteringSelect automatically selects first value.
我如何允许用户将空值设置为FilteringSelect?
How could I allow user to set empty value into FilteringSelect?
推荐答案
您应该添加一个空的条目(或者是否可能?我知道工作)到你的数据存储加载后(我会把它放在一开始),但在启动之前。
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.
FilteringSelect的必需问题很奇怪,因为它不会让您选择任意值 - 它必须是数据存储中的条目。然而,如果不需要它不应该不在乎吗?有时候Dojo很奇怪。
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.
这篇关于Dojo:选择FilteringSelect的空值,而required = false的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!