Skip to main content

Component | Number Input

Render a number input box.

ui.numberInput("number-input-key", { 
label: "Enter your age",
onEnter: (value) => console.log(value)
})

This component is a light wrapper on top of ui.textInput that is limited to number inputs.

Learn more about working with inputs.

API reference

Function signature

ui.numberInput(
id: string,
properties?: Partial<{
label: string,
description: string,
required: boolean,
initialValue: number | null,
validate: (value: number | null) => string | void,
onEnter: (value: number | null) => void,
style: Style
}>
)

Parameters

id

required string
A unique identifier for the component. This is necessary so that Compose can properly pass user actions back to the component.

properties.label

optional string

The label to display above the number input. If not provided, the label will be inferred from the id.


properties.description

optional string

A description to display between the label and number input box.


properties.required

optional boolean

Validate that the number input is not empty before submitting the form it's part of or calling it's onEnter hook. Defaults to true.


properties.initialValue

optional number | null

The initial value of the number input. Defaults to null. You can also update the value of the number input at any time using the page.setInputs() method.


properties.validate

optional (value: number | null) => string | void
Validate the number input value before submitting it. If the function returns a string, it will be displayed as an error message.

properties.onEnter

optional (value: number | null) => void
A callback function that is called when the user presses enter in the number input.

properties.style

optional Style

Directly style the underlying element using CSS. See the styling guide for more details on available style properties.