Skip to content

InputNumber

Rules

Basic Example

js
const rule = {
    type: "InputNumber",
    field: "price",
    title: "Price",
    value: 1,
    props: {
        precision: 2
    },
}

Props Configuration Examples

Set Value Range

js
const rule = {
    type: "InputNumber",
    field: "quantity",
    title: "Purchase Quantity",
    value: 1,
    props: {
        min: 1,
        max: 100,
        step: 1,
    },
}

Precision Control

js
const rule = {
    type: "InputNumber",
    field: "price",
    title: "Product Price",
    value: 99.99,
    props: {
        precision: 2,
        step: 0.01,
        placeholder: "Please enter price",
    },
}

Prefix and Suffix Labels

js
const rule = {
    type: "InputNumber",
    field: "price",
    title: "Price",
    value: 0,
    props: {
        addonBefore: "¥",
        addonAfter: "Yuan",
        min: 0,
        precision: 2,
    },
}

Disable Control Buttons

js
const rule = {
    type: "InputNumber",
    field: "score",
    title: "Score",
    value: 0,
    props: {
        controls: false,
        min: 0,
        max: 100,
        placeholder: "Enter score (0-100)",
    },
}

Events Examples

Listen to Value Changes

js
const rule = {
    type: "InputNumber",
    field: "price",
    title: "Product Price",
    value: 0,
    props: {
        min: 0,
        precision: 2,
        placeholder: "Please enter price",
    },
    on: {
        change: (value) => {
            console.log('Value changed:', value);
        },
        pressEnter: (e) => {
            console.log('Pressed Enter:', e);
        },
        step: (value, info) => {
            console.log('Clicked arrow:', value, info);
        },
    },
}

Calculate Total Price After Value Changes

js
const rule = [
    {
        type: "InputNumber",
        field: "price",
        title: "Unit Price",
        value: 0,
        props: {
            min: 0,
            precision: 2,
        },
        inject: true,
        on: {
            change: ($inject, value) => {
                // Automatically calculate the total price
                const quantity = $inject.api.getValue('quantity') || 1;
                const total = value * quantity;
                $inject.api.setValue('total', total.toFixed(2));
            },
        },
    },
    {
        type: "InputNumber",
        field: "quantity",
        title: "Quantity",
        value: 1,
        props: {
            min: 1,
        },
        inject: true,
        on: {
            change: ($inject, value) => {
                // Automatically calculate the total price
                const price = $inject.api.getValue('price') || 0;
                const total = price * value;
                $inject.api.setValue('total', total.toFixed(2));
            },
        },
    },
    {
        type: "InputNumber",
        field: "total",
        title: "Total Price",
        props: {
            disabled: true,
            precision: 2,
        },
    },
]

Complete configuration items: Ant-design-vue_InputNumber

value :Number

Props

MemberDescriptionTypeDefault
addonAfterInput with label, set suffix labelslot-
addonBeforeInput with label, set prefix labelslot-
autofocusAuto focusbooleanfalse
borderedWhether to have borderbooleantrue
controlsWhether to show increase/decrease buttonsbooleantrue
decimalSeparatorDecimal separatorstring-
disabledDisabledbooleanfalse
formatterSpecify the format of the value displayed in the input boxfunction(value: number | string, info: { userTyping: boolean, input: string }): string-
keyboardWhether to enable keyboard shortcutsbooleantrue
maxMaximum valuenumberInfinity
minMinimum valuenumber-Infinity
parserSpecify how to convert back to number from formatter, used together with formatterfunction( string): number-
precisionPrecision of valuenumber-
prefixInput with prefix iconslot-
sizeInput box sizestring-
statusSet validation status'error' | 'warning'-
stepStep value for each change, can be decimalnumber|string1
stringModeString value mode, after enabling supports high precision decimals. At the same time, change event will return string typebooleanfalse
upIconCustom up arrow iconslot<UpOutlined />
downIconCustom down arrow iconslot<DownOutlined />

Events

Event NameDescriptionCallback Parameters
changeCallback when value changesFunction(value: number | string)
pressEnterCallback when pressing Enterfunction(e)
stepCallback when clicking up/down arrows(value: number, info: { offset: number, type: 'up' | 'down' }) => void

FormCreate is an open-source project released under the MIT License. Free for personal and commercial use.