Unit Selector state variables represent an input that allows the user to select the units to be displayed by the unitInput and unitOuput state variables of the same unitClass.
Unit Selector state variables inherit from the SelectorInputSv and support a specific type of options. The option value is the internal unit (e.g. 'kg'), and the text is what the user should see (e.g. "kg." or "Kilograms"). The unit values must be from those defined in Units.
By default, the selector renders as a popup list of units for the user to select. The currently selected unit is highlighted. The selector can also render as a set of radio buttons by specifying the radio attribute. The radio buttons can be horizontal or vertical, and the text labels can be on either side for both orientations by specifying one of the following attributes:
labelToplabelRightlabelBottom (default)labelLeftThe options are not saved when a Unit Selector Input is saved to storage. Only the selector value is saved. It is expected that the app code will reestablish the current unit options and upgrade the saved values as required.
Selector Input state variables maintain a public child state variable that can be referred to using the subname options (e.g., myPage_myUnitSelector_options). The child state variable's value is an array of options objects containing the following properties:
textvalueThe child state variable can be used to determine when the state variable options change (as opposed to the state variable value).
'unitSelector', class: UnitSelSvctl.createPage({
...,
stateVarInfo:[
{
type: 'unitSelector',
options: [{value:<i>valueString</i>, text:<i>textString</i>}, ...]
},
],
});
infoinfo object can contain the following properties, but subclasses of StateVar may have additional properties:info properties.info properties.info properties.options (optional)text (optional)text is omitted, then value coerced to a string is used.value (required) The value of the state variable if this option is selected.
If an element is a number, the displayed text is the number coerced to a string, and the value is the element. If an element is a string, it is used for both the displayed text and value.
Note: The component() method returns a SelectorInputSvCmp.
fmtUnit()fmtUnit()
Returns a unit abbreviation appropriate to the value. See Units.
valueA string containing the unit abbreviation.
UnitCtlSv.currentUnit()UnitSelSv.currentUnit(unitClass);
Return the current unit value from the unitSelector associated with unitClass. Returns a unit option value. This is typically string (e.g., 'kg').
unitClassunitClass string for the unitSelector state variable that controls which unit sibling is current for state variables in this unitClass.An option value.
UnitCtlSv.getUnitSelector()UnitSelSv.getUnitSelector(unitClass);
Return the unitSelector state variable that controls unitClass.
unitClassunitClass string for the unitSelector state variable that controls which unit sibling is current for state variables in this unitClass.UnitCtlSv.convertCurrentUnits()UnitSelSv.convertCurrentUnits(value, fromUnits, unitClass);
Return the value converted from fromUnits units to the units selected by the current value of the unitSelecotor state variable for the unitClass.
unitClass string for a unitSelector.A Number.