Keypad Reference

Table of contents


Introduction

MVCS provides a customizable popup keypad. The keypad can contain numbers, letters, or symbols in a flexible arrangement. It provides easier data entry for specific inputs and a standard interface across all platform types.

The keypad is controlled using the keypad object. The keypad.open() method will open a custom keypad, while the keypad.number() method will open a numeric keypad. Both methods return a Promise for receiving the results. The keypad.open() method is the most flexible. It provides a custom key layout grid, and custom key handling.

The keypad is implemented as the overlay page keypad, which is separate from the dialog page. The page has the state variables keypad_current (a modelObject holding the current layout, key function, resolve function, and initial value), keypad_className (a modelValue that drives the show/hide slide animation, 'keypad-show' or 'keypad-hide'), keypad_value (a textOutput holding the displayed value string), and keypad_units (a textOutput holding the displayed units string). The page is opened by keypad.open() through nav.overlayPage('keypad', {layout, value, units, keyFn, resolve}); the argument properties are the keypad.open() arguments plus the resolve function of the returned Promise. Applications should use the keypad methods rather than opening the page directly.


Exported identifiers

keypad

Syntax

import {keypad} from 'common/mvcs/export.js';

The keypad object provides methods and properties to control the popup keypad.


keypad methods

number()

Syntax

keypad.number(numFmt, value, units)
keypad.number(numFmt, value)
keypad.number(numFmt)

Opens a numeric keypad that can handle numbers specified by the numFmt argument. If the value argument is provided, it sets the initial value. Otherwise, the intial value is zero. If the units argument is provided, then it is used to display a unit abbreviation following the value.

The numFmt argument is a NumFmt object. If the format allows both positive and negative numbers the keypad will include +/- key to change the sign of the keypad value. If the format allows fractional digits than a . key will be provided and the keypad will automatically enter a '.' after the maximum integer digits have been entered.

Internally the keypad value is a string, which for formats that allow negative numbers starts with a + or - sign; the Promise is resolved with the value converted by Number(). The keypad.number() method returns a Promise. The Promise is resolved with the final value as a number. If the user cancels the data entry, the value is reset to the initial value and the Promise is resolved with it (the Promise is never rejected).

Parameters

Return value

A Promise that is resolved with the keypad value, as a number, when the user dismisses the keypad. If the user cancels, the Promise is resolved with the initial value; it is never rejected.


numFmtLayout()

Syntax

keypad.numFmtLayout(numFmt)

Returns a numeric keypad layout array appropriate to a given NumFmt object. The numFmt argument is a NumFmt object. If the format allows both positive and negative numbers the keypad will include +/- key to change the sign of the keypad value. If the format allows fractional digits than a . key will be included.

Parameters

Return value

An keypad layout array suitable for the keypad.open() method.


open()

Syntax

keypad.open(layout, value, units, keyFn)
keypad.open(layout, value, units)
keypad.open(layout, value)
keypad.open(layout)

Open a custom keypad. The layout argument is an array of button rows. Each row is an array of button symbol strings or an object containing both text and value properties. A null or other falsy entry produces a blank cell. If the value argument is provided, it sets the initial value. Otherwise, the intial value is zero. If the units argument is provided, then it is used to display a unit abbreviation following the value. Only one keypad can be open at a time.

If the keyFn argument is provided, it is a function that is called for each new key press. It is given the current keypad value and the value associated with a key, and it returns an updated keypad value. The function is allowed to reject a particular key press by returning the same keypad value it was given. If no keyFn argument is provided, then the value of a pressed key is appended to the current keypad value; the default does not handle backspace.

Parameters

Return value

A Promise that is resolved with the final keypad value string when the user dismisses the keypad with "Done". If the user presses "Cancel", the value is reset to the initial value and the Promise is resolved with it; the Promise is never rejected. If a keypad is already open, the call does nothing and returns undefined.


stdNumLayout()

Syntax

keypad.stdNumLayout(left, right)
keypad.stdNumLayout(left)
keypad.stdNumLayout()

Returns a numeric keypad layout array for a standard phone style numeric keypad. The button on the lower left will be blank unless a non-null value is provided in the left argument. The button on the lower right will be a backspace symbol unless a value other than undefined is provided in the right argument (null leaves it blank). As with the keypad.open() method layout entries, the arguments can be a single string or an object containing both text and value properties.

Parameters

Return value

An keypad layout array suitable for the keypad.open() method.


keypad properties

backspaceKey

A key layout entry representing a backspace key.

Value

An object {text:'&leftArrowD;', value:'backspace'}.


plusMinusKey

A key layout entry representing a +/- or change sign key.

Value

The string '+/-'.


pointKey

A key layout entry representing a decimal point key.

Value

An object {text:'•', value:'.'}.