A unit input (unitInput) state variable represents a user numeric input value with multiple possible units. The app may provide the user a choice of their desired units for the number. The app can also choose which units it wants to compute with independent of the user's choice. Each rendered component will display according to the format and limits specified for the chosen unit in the state variable.
The unit input contains several child numericInput state variables, one for each unit is supports. Each child state variable is published with a subName corresponding to its unit (e.g., 'myPage_mySv_kg' and 'myPage_mySv_lb'). When one child state variable changes, the others are updated with the new value converted to their respective units.
Each unit input has an associated unitClass string. Each unitClass is associated with a unitSelector state variable. The unitSelector state variable controls which unit each rendered component will be displayed to the user. Many unitInput state variables can have the same unitClass, and, therefore will be controlled by the same unitSelector.
The unitInput state variable's component instance will display the currently selected unit sibling. If the showUnits attribute or the '{{...@}}' template syntax is used, the component will also display the appropriate unit abbreviations for the currently selected unit.
The app code or a component template may also refer to a specific child numericInput state variable. Any modification to that child will also update its siblings with converted values.
MVCS supports three types of numeric input mechanisms: a physical or virtual keyboard, a popup keypad, or a thumbwheel. The app Settings page can select the desired input mechanism for each device type by setting the sv.set_numInputType state variable. See Standard Settings Page.
'unitInput', class: UnitInputSvctl.createPage({
...,
stateVarInfo:[
{type:'unitInput', ...},
],
})
info
An object containing the state variable properties. The info object can contain the following properties, but subclasses of StateVar may have additional properties:
info properties.info properties.info properties.unitClassunitClass string for the unitSelector that controls which unit sibling is current for this state variable.unitsinfo object. The first unit info object that supplies a max key is considered the primary unit sibling. If no child state variable supplies a max key, then the first key is considered primary. If a sibling does not declare a max or min value, then the max and/or min values from the primary sibling will be converted to the max and min values for that sibling.dflt (optional)info.units entry has no dflt of its own. Other siblings convert their defaults from the primary unit unless they supply their own dflt.The object for each unit has the following keys:
fmtfmtStr). A NumFmt instance will be created using this string along with the unit's min and max (converted from the primary unit if not supplied). Only the primary unit may omit fmt (a format string of '8' is then assumed); every other unit must supply a format string. The primary unit may alternatively supply a NumFmt instance.min (optional)fmt parameter.max (optional)fmt parameter.dflt (optional)Note: The component() method is inherited from OutputSv and wraps render(). The parent's render() returns a <When> that renders a <StateVar> for the current unit sibling, and re-renders it when the unitSelector value changes. The component that is ultimately displayed is the current sibling's NumInputSvCmp, so the numericInput component attributes apply.
The following methods are shared with unitOutput and operate on the current unit sibling (curSv):
val([value]), isValid(...), setDflt(), fmtVal(), fmtUnit(), and userChange(value).getUnitSv(unit)unit. Asserts if there is none.siblings()unitSiblingId(unit)unit (<id>_<unit>).getSavedState()getSavedState()
Returns the state of the current unit sibling state variable. If the current sibling's value is not valid, its default is returned as the value.
Returns an object with the following keys:
unitvaluesetSavedState()setSavedState(state)
Sets the state variable to the internal state specified by state. If state is not an object with a unit, or the unit is not one of this state variable's units, the state variable is set to its default (the latter is logged). If state.value is not valid, the sibling for that unit is set to its default.
stategetSavedState().isValidState()isValidState(state)
Returns true if state is an object whose unit is one of this state variable's units and whose value is valid for that unit's sibling.
isNumberNot set on the unitInput parent. It is true for each unit sibling numericInput.
A Boolean.
isUnitAlways true for unitInput.
A Boolean.
isUnitParentAlways true for unitInput.
A Boolean.
unitClassThe unitClass string for the unitSelector that controls which unit sibling is current for this state variable.
A String.
isDisabledGets the disabled state of the current unit sibling. Setting it sets the disabled state of every sibling, so the state holds whichever unit is displayed.
A Boolean.
min, max, fmtGetters that return the current unit sibling's min, max, and fmt. Setting any of them on the parent asserts (it fails); set them on a sibling instead. Setting min or max on a sibling converts and sets the limit on every sibling.
classNameGets/sets the className of the current sibling; setting applies to all siblings.
unitSiblingsA Map from unit to sibling state variable.
numInputTypeThe numInputType attribute establishes a particular user input type that overrides the sv.set_numInputType state variable. If not specified, the current value of sv.set_numInputType is used. The values can be:
'keyboard''keypad''thumbwheel'A String.
fmtA NumFmt instance or format string that overrides the current sibling's format for this component.
plusMinusIf plusMinus is true, then "-" and "+" buttons will apear to the left and right of the input. Pressing one of the buttons will increment or decrement the value by fmt.rndMult.
A Boolean.
keyboard numInputType, the numericInput Component will render an <input type="number"> with the value, max, min, and step attributes set according to the respective current numeric input state variable properties.<input> element may be converted to <input type="text"> when it loses focus.value attribute will be synchronized with the current unit sibling value. The min, max and step attributes will be synchronized with respective properties in the NumFmt instance in the current unit sibling's fmt property.<input> element will have a className that contains 'svIo_numInput'.numInputType, the numericInput Component will render a <span>.<span> contents will be synchronized with the state variable value.