1. Introduction
The Uize.Widget.Options class manages state for a group of option buttons, with support for dynamically rebuilding the UI when the values set changes.
DEVELOPERS: Chris van Rensburg, Jan Borgersen, Ben Ilegbodu, original code donated by Zazzle Inc.
The Uize.Widget.Options module defines the Uize.Widget.Options widget class, a subclass of Uize.Widget.
2. Instance Methods
2.1. forAll
An iterator method that is provided as a convenience and that lets you iterate over all the option buttons for the instance.
SYNTAX
myInstance.forAll (iterationFUNC);
The function specified in the iterationFUNC parameter will be called on each iteration and can expect to receive two parameters for the current iteration: an object reference to the option button widget, and an integer representing the index of the option. The function does not need to return any value. However, if the function wishes to terminate the iteration, it can return the boolean value false.
EXAMPLE
myOptionsWidget.forAll (
function (optionButton,optionNo) {
optionButton.set ({enabled: optionNo % 2 ? 'inherit' : false});
}
);
In the above example, the forAll instance method is being used to iterate over all the option buttons in order to disable every second option button - not a terribly practical example, but it illustrates the usage.
2.2. getValueNoFromValue
3. Instance Events
3.1. Before Value Change
This event fires just as an option button is clicked, but before the value set-get property for the instance is updated.
This event offers the handler the opportunity to cancel the value change. The event contains a "value" property (which is the new value that would be set) and a "valueNo" property (which is the index of the new value that would be set). To cancel the set action, the handler can set the event object's "cancel" property to true. The handler can inspect the "value" and "valueNo" properties of the event to determine if the value change should be permitted.
3.2. Option Event
Fires each time an event fires for one of the option button child widgets.
When this event fires, the event object will have a "value" property whose value corresponds to the value associated with the option, as well as a "childEvent" property that carries the event object associated with the option button event.
4. Set-get Properties
the initial value is undefined |
NOTES
4.1. optionWidgetClass
An object reference to a widget class that should be used for the option buttons.
By default, the Uize.Widget.Button class is used for the option buttons. However, in some cases you may wish to use a class with richer functionality for the option buttons. You can create such a class by subclassing the Uize.Widget.Button class. If the widget class to be used for the option buttons is not a subclass of Uize.Widget.Button, then it will at least have to provide an equivalent interface in order to work with the Uize.Widget.Options class.
NOTES
when this property is set to null or left undefined, then the Uize.Widget.Button class will be used for option buttons | |
see the companion optionWidgetProperties set-get property | |
the initial value is undefined |
4.2. optionWidgetProperties
An object, specifying values for set-get properties that should be used when creating option button child widgets.
The optionWidgetProperties property lets you specify values for set-get properties that will be common to all option button widgets that are created. This can be useful in cases where you are using the optionWidgetClass set-get property to use a widget class other than Uize.Widget.Button for the option buttons, and where that other widget class may provide further configurability through additional set-get properties beyond what the Uize.Widget.Button class provides. In such cases, option button instances that are created for a particular Uize.Widget.Options instance can be configured for that instance by specifying set-get property values through the optionWidgetProperties property.
NOTES
see the companion optionWidgetClass set-get property | |
the initial value is false |
4.3. setValueOnMouseover
A boolean, indicating whether or not the value of the value set-get property should be set when the user rests the mouse over an option, instead of the values of the tentativeValue and tentativeValueNo set-get properties.
When this property is set to true, the value set-get property will be set when the user rests the mouse over an option. When this property is set to false, null, 0, or left undefined, then the values of the tentativeValue and tentativeValueNo properties will be set.
When setValueOnMouseover is set to true, the user will not be required to click in order for a selection to be made. In such a case, if the tentativeRestTime property is set to 0, then the value property will be set immediately on mousing over an option. When tentativeRestTime is set to a value greater than 0, then the user will have to rest the mouse on the option for the amount of time specified by the tentativeRestTime property before the value property is set. Of course, the user can still click immediately after mousing over the option to expedite selection.
4.4. tentativeRestTime
An integer, representing the time (in milliseconds) that the user must remain moused over an option button before the tentativeValue set-get property will be set to the value corresponding to that button.
NOTES
the special value of 0 indicates that the tentativeValue mechanism should be disabled | |
the initial value is 0 |
4.5. tentativeValue
A value of any type, that represents the current value that is tentatively being set / considered by the user.
NOTES
the initial value is null | |
whenever the value set-get property is set, this property is also set to the same value | |
in "resting" state (ie. when the user is not interacting with the widget), this property will have the same value as the value set-get property |
4.6. tentativeValueNo
An integer, representing the index of the current tentativeValue in the values set.
NOTES
the initial value is -1 | |
when no value is selected, this property is set to -1 | |
| this property is read-only |
4.7. value
A simple type value (string, boolean, or number), that should either match one of the values in an array of simple type values specified by the values set-get property, or should match the name property of one of the objects in an array of object type values specified by the values set-get property.
NOTES
the initial value is null | |
whenever this property is set, the tentativeValue set-get property is set to the same value |
4.8. valueNo
An integer, representing the index of the current value in the values set.
NOTES
the initial value is -1 | |
when no value is selected, this property is set to -1 | |
| this property is read-only |
4.9. values
An array of simple type values (string, boolean, or number) or objects, representing the value set for the widget.
EXAMPLE 1
myOptions.set ({values:['orange','avocadoPear','sweetPotato']});
In the above example, the values for myOptions is being set to an array of strings. In order to select the sweet potato value, one would use the statement myOptions.set ({value:'sweetPotato'}).
EXAMPLE 2
myOptions.set ({
values:[
{
name:'orange',
displayName:'Orange',
category:'fruit'
},
{
name:'avocadoPear',
displayName:'Avocado Pear',
category:'fruit'
},
{
name:'sweetPotato',
displayName:'Sweet Potato',
category:'vegetable'
}
]
});
When an array of objects is specified for the values set-get property, each object should contain a name property. Then, when setting a value for the value set-get property, the object from the values array will be selected whose name property matches the value of the value set-get property. In the above example, the values for myOptions is being set to an array of objects. In order to select the sweet potato value now, one would use the statement myOptions.set ({value:'sweetPotato'}).
NOTES
| if this property is changed once the widget is already wired, then the widget will be unwired and then wired again | |
the initial value is [] (an empty array) |