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


fmtUnit()

Syntax

fmtUnit()

Returns a unit abbreviation appropriate to the value. See Units.

Parameters

Return value

A string containing the unit abbreviation.


Static methods

UnitCtlSv.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').

Parameters

Return value

An option value.


UnitCtlSv.getUnitSelector()

Syntax

UnitSelSv.getUnitSelector(unitClass);

Return the unitSelector state variable that controls unitClass.

Parameters

Return value


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