The set of options for our select item. Roughly corresponds to
the html <option> tag.
dijit.form._FormSelectWidget.store
type
dojo.data.api.Identity
summary
A store which, at the very least impelements dojo.data.api.Identity
to use for getting our list of options - rather than reading them
from the <option> html tags.
dijit.form._FormSelectWidget.query
type
object
summary
A query to use when fetching items from our store
dijit.form._FormSelectWidget.queryOptions
type
object
summary
Query options to use when fetching from the store
dijit.form._FormSelectWidget.onFetch
type
Function
summary
A callback to do with an onFetch - but before any items are actually
iterated over (i.e. to filter even futher what you want to add)
dijit.form._FormSelectWidget.sortByLabel
type
Boolean
summary
Flag to sort the options returned from a store by the label of
the store.
dijit.form._FormSelectWidget.loadChildrenOnOpen
type
Boolean
summary
By default loadChildren is called when the items are fetched from the
store. This property allows delaying loadChildren (and the creation
of the options/menuitems) until the user clicks the button to open the
dropdown.
dijit.form._FormSelectWidget.getOptions
type
Function
parameters:
valueOrIdx: (typeof anything)
If passed in as a string, that string is used to look up the option
in the array of options - based on the value property.
(See dijit.form.__SelectOption).
If passed in a number, then the option with the given index (0-based)
within this select will be returned.
If passed in a dijit.form.__SelectOption, the same option will be
returned if and only if it exists within this select.
If passed an array, then an array will be returned with each element
in the array being looked up.
If not passed a value, then all options will be returned
dijit.form.__SelectOption = function(){ // value: String // The value of the option. Setting to empty (or missing) will // place a separator at that location // label: String // The label for our option. It can contain html tags. // selected: Boolean // Whether or not we are a selected option // disabled: Boolean // Whether or not this specific option is disabled this.value = value; this.label = label; this.selected = selected; this.disabled = disabled; }
dojo.declare("dijit.form._FormSelectWidget", dijit.form._FormValueWidget, { // summary: // Extends _FormValueWidget in order to provide "select-specific" // values - i.e., those values that are unique to
Adds an option or options to the end of the select. If value
of the option is empty or missing, a separator is created instead.
Passing in an array of options will yield slightly better performance
since the children are only loaded once.
if(!dojo.isArray(valueOrIdx)){ valueOrIdx = [valueOrIdx]; } var oldOpts = this.getOptions(valueOrIdx); dojo.forEach(oldOpts, function(i){ // We can get null back in our array - if our option was not found. In // that case, we don't want to blow up... if(i){ this.options = dojo.filter(this.options, function(node, idx){ return (node.value !== i.value || node.label !== i.label); }); this._removeOptionItem(i); } }, this); this._loadChildren();
summary
Removes the given option or options. You can remove by string
(in which case the value is removed), number (in which case the
index in the options array is removed), or select option (in
which case, the select option with a matching value is removed).
You can also pass in an array of those values for a slightly
better performance since the children are only loaded once.
Updates the values of the given option. The option to update
is matched based on the value of the entered option. Passing
in an array of new options will yeild better performance since
the children will only be loaded once.
dijit.form._FormSelectWidget.setStore
type
Function
parameters:
store: (typeof dojo.data.api.Identity)
The store you would like to use - it MUST implement Identity,
and MAY implement Notification.
selectedValue: (typeof anything)
The value that this widget should set itself to *after* the store
has been loaded
fetchArgs: (typeof Object)
The arguments that will be passed to the store's fetch() function
if(fetchArgs.onFetch){ items = fetchArgs.onFetch.call(this, items, opts); } // TODO: Add these guys as a batch, instead of separately dojo.forEach(items, function(i){ this._addOptionForItem(i); }, this);
// Set our value (which might be undefined), and then tweak // it to send a change event with the real value this._loadingStore = false; this.set("value", "_pendingValue" in this ? this._pendingValue : selectedValue); delete this._pendingValue;
Sets the store you would like to use with this select widget.
The selected value is the value of the new store to set. This
function returns the original store, in case you want to reuse
it or something.
var opts = this.getOptions() || []; if(!this.multiple && opts.length){ // Mirror what a select does - choose the first one var opt = dojo.filter(opts, function(i){ return i.selected; })[0]; if(opt && opt.value){ return opt.value }else{ opts[0].selected = true; return opts[0].value; } }else if(this.multiple){ // Set value to be the sum of all selected return dojo.map(dojo.filter(opts, function(i){ return i.selected; }), function(i){ return i.value; }) || []; } return "";
summary
Returns the value of the widget by reading the options for
the selected flag
var store = this.store, label = store.getLabel(item), value = (label ? store.getIdentity(item) : null); return {value: value, label: label, item:item}; // dijit.form.__SelectOption
summary
Returns an option object based off the given item. The "value"
of the option item will be the identity of the item, the "label"
of the option will be the label of the item. If the item contains
children, the children value of the item will be set
var store = this.store; if(!store.isItemLoaded(item)){ // We are not loaded - so let's load it and add later store.loadItem({item: item, onComplete: function(i){ this._addOptionForItem(item); }, scope: this}); return; } var newOpt = this._getOptionObjForItem(item); this.addOption(newOpt);
this.inherited(arguments); var store = this.store, fetchArgs = {}; dojo.forEach(["query", "queryOptions", "onFetch"], function(i){ if(this[i]){ fetchArgs[i] = this[i]; } delete this[i]; }, this); if(store && store.getFeatures()["dojo.data.api.Identity"]){ // Temporarily set our store to null so that it will get set // and connected appropriately this.store = null; this.setStore(store, this._oValue, fetchArgs); }
// summary: // User-overridable function which, for the given option, adds an // item to the select. If the option doesn't have a value, then a // separator is added in that place. Make sure to store the option // in the created option widget.
summary
User-overridable function which, for the given option, adds an
item to the select. If the option doesn't have a value, then a
separator is added in that place. Make sure to store the option
in the created option widget.
// summary: // Overridable function which will set the display for the // widget. newDisplay is either a string (in the case of // single selects) or array of strings (in the case of multi-selects)
summary
Overridable function which will set the display for the
widget. newDisplay is either a string (in the case of
single selects) or array of strings (in the case of multi-selects)
// summary: // a function that will "fake" loading children, if needed, and // if we have set to not load children until the widget opens. // items: // An array of items that will be loaded, when needed
summary
a function that will "fake" loading children, if needed, and
if we have set to not load children until the widget opens.
// summary: // a function that can be connected to in order to receive a // notification that the store has finished loading and all options // from that store are available
summary
a function that can be connected to in order to receive a
notification that the store has finished loading and all options
from that store are available
dijit.form.__SelectOption = function(){ // value: String // The value of the option. Setting to empty (or missing) will // place a separator at that location // label: String // The label for our option. It can contain html tags. // selected: Boolean // Whether or not we are a selected option // disabled: Boolean // Whether or not this specific option is disabled this.value = value; this.label = label; this.selected = selected; this.disabled = disabled;
summary
dijit.form.__SelectOption.value
type
String
summary
The value of the option. Setting to empty (or missing) will
place a separator at that location
dijit.form.__SelectOption.label
type
String
summary
The label for our option. It can contain html tags.