Skip to content

IntegerInput

<IntegerInput> renders an <input type="number"> element where the value prop is bound and which includes all of Formula’s required handlers. It does not accept decimal values. If the user attempts to enter one, it will be rounded to the nearest integer.

The value NaN is used when the field is blank. It’s also used for “intermediate values”: strings which aren’t themselves a valid number but might become one after additional keystrokes. For example, +, -, or -..

const form = useForm({
initialValues: {
myNum: NaN // start as blank
}
});
return (
<IntegerInput field={form("myNum")} />
)
function IntegerInput(props: {
// The field to associate with this input
field: FormField<number>
} & Omit<DefaultInputProps, "type" | "value">)

<IntegerInput> supports all props of the native <input>, except type which is hardcoded to number, and value which is bound automatically.