Unit Selector State Variable Reference

Table of contents


Introduction

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:

The 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.

Child state variables

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:

The child state variable can be used to determine when the state variable options change (as opposed to the state variable value).

Constructor

Syntax

ctl.createPage({
	...,
	stateVarInfo:[
		{
			type: 'unitSelector',
			options: [{value:<i>valueString</i>, text:<i>textString</i>}, ...]
		},
	],
});

Parameters


Instance methods

Inherited methods

Note: The component() method returns a UnitSelSvComponent, a subclass of SelectorInputSvCmp. If the component has both the valueOnly and showUnits attributes, it renders only a <span> containing the unit abbreviation (fmtUnit()) of the current unit; otherwise it renders as a selector.


fmtUnit()

Syntax

fmtUnit()

Returns the unit abbreviation (units.fmtAbbrev) for the currently selected unit (the state variable value). See Units. The method takes no parameters.

Return value

A string containing the unit abbreviation.


Instance properties

Inherited properties

isUnitCtl

Always true for unitSelector.

Value

A Boolean.

unitClass

The unitClass string for this selector.

Value

A String.


Static methods

UnitSelSv.currentUnit()

Syntax

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'). Throws a TypeError if no unitSelector exists for unitClass.

Parameters

Return value

An option value.


UnitSelSv.getUnitSelector()

Syntax

UnitSelSv.getUnitSelector(unitClass);

Return the unitSelector state variable that controls unitClass, or undefined if there is none.

Parameters

Return value

A UnitSelSv instance or undefined.


UnitSelSv.convertCurrentUnits()

Syntax

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.

Parameters

Return value

A Number.


Component attributes

Inherited attributes


DOM element properties