Now.js Framework Documentation

Now.js Framework Documentation

NumberElementFactory

EN 04 Sep 2026 01:40

NumberElementFactory

NumberElementFactory Builds a formatted numeric input. Renders as type="text" rather than a native number input, because native number inputs cannot show thousand separators or a fixed number of decimals — the trade-off is that this factory does its own keystroke and paste filtering to keep the value numeric.

Generated from source on 2026-08-21. Descriptions come from JSDoc in the file.
Re-run docs_scaffold when the code changes; hand edits are lost on regeneration

Source

  • File: Now/js/NumberElementFactory.js (667 lines)
  • Form: ES class

Public methods (10)

static applyFormatting(instance)

Reformat the field's current value, e.g. after blur. Does nothing when the field is empty, so an untouched required field is not turned into a formatted "0".

static extractCustomConfig(element, def, dataset)

Read the numeric options a single element declares. Falls back to this.config rather than def alone, since def can arrive empty from enhance(). data-decimals is accepted as an alias for data-precision.

static formatNumber(value, config)

Format a number for display, applying grouping and precision. A string input is parsed first via parseNumber, so this accepts either a raw number or already-typed text.

static formatValue(value, element, config)

Validate and format a value for the element, reporting a required-field error.

static handlePaste(e, instance)

Filter a pasted value down to its numeric content before it lands in the field.

static handleSpecialKeys(e, instance)

Let navigation and editing keys through regardless of the numeric filter.

static isAllowedKey(e, config)

Whether a typed character is legal for the current numeric config. A digit is always allowed; the decimal separator and minus sign are only allowed when config permits them and one is not already present.

static parseNumber(value, config)

Parse a formatted string back into a plain number. A number is passed through as-is (NaN stays NaN); an empty, null or undefined value yields NaN rather than 0, so "no value" and "zero" stay distinguishable.

static setupElement(instance)

Prepare a number field, switching its rendered type to text. Uses getAttribute('type') rather than the type property, because the browser normalises unknown type values to 'text' on the property but not on the attribute — and only <input> allows the property to be set at all.

static setupEventListeners(instance)

Bind the keydown, paste and input handlers that keep the value numeric. Validation runs debounced, same as the base ElementFactory.

Data attributes used

data-allow-negative · data-decimal-separator · data-decimals · data-grouping-separator · data-pad-to-precision · data-precision · data-round-values · data-select-on-focus · data-use-grouping

Depends on

ElementFactory · ElementManager · EventSystemManager · FormError · Utils