Skip to content

InputNumber

Rules

Basic Example

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

Props Configuration Examples

Set Minimum and Maximum Values

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

Set Step and Precision

js
const rule = {
    type: "InputNumber",
    field: "price",
    title: "Product Price",
    value: 0,
    props: {
        min: 0,
        step: 0.01,
        placeholder: "Enter price",
        clearable: true,
    }
}

Disabled State

js
const rule = {
    type: "InputNumber",
    field: "total",
    title: "Total Price",
    value: 0,
    props: {
        disabled: true,
    }
}

Hide Buttons

js
const rule = {
    type: "InputNumber",
    field: "score",
    title: "Score",
    value: 0,
    props: {
        showButton: false,
        min: 0,
        max: 100,
    }
}

Events Examples

Handle Value Changes

js
const rule = {
    type: "InputNumber",
    field: "quantity",
    title: "Purchase Quantity",
    value: 1,
    props: {
        min: 1,
        max: 100,
    },
    on: {
        'update:value': (value) => {
            console.log('Value changed:', value);
        },
        blur: () => {
            console.log('Lost focus');
        },
        focus: () => {
            console.log('Gained focus');
        },
    },
}

Linkage Calculate Total Price

js
const rule = [
    {
        type: "InputNumber",
        field: "quantity",
        title: "Purchase Quantity",
        value: 1,
        props: {
            min: 1,
            max: 100,
        },
        inject: true,
        on: {
            'update:value': ($inject, value) => {
                // Calculate total price
                const price = $inject.api.getValue('price') || 0;
                $inject.api.setValue('total', (price * value).toFixed(2));
            },
        },
    },
    {
        type: "InputNumber",
        field: "price",
        title: "Unit Price",
        value: 0,
        props: {
            min: 0,
            step: 0.01,
        },
        inject: true,
        on: {
            'update:value': ($inject, value) => {
                // Calculate total price
                const quantity = $inject.api.getValue('quantity') || 0;
                $inject.api.setValue('total', (value * quantity).toFixed(2));
            },
        },
    },
    {
        type: "InputNumber",
        field: "total",
        title: "Total Price",
        value: 0,
        props: {
            disabled: true,
        },
    },
]

Complete configuration items: naive-ui_InputNumber

value :Number

Props

NameTypeDefault ValueDescription
borderedbooleantrueWhether it has border
clearablebooleanfalseWhether it can be cleared
disabledbooleanfalseWhether disabled
keyboard{ ArrowUp?: boolean, ArrowDown?: boolean }{}Control allowed keyboard operations, setting property value to false will disable corresponding keyboard operation
loadingbooleanundefinedWhether to show loading icon, setting to non undefined will occupy space
maxnumberundefinedMaximum value
minnumberundefinedMinimum value
placeholderstring'请输入'Hint message
show-buttonbooleantrueWhether it has buttons
size'small' | 'medium' | 'large''medium'Input size
stepnumber1Step for each change, can be decimal
update-value-on-inputbooleantrueWhether to change value during input when input value is valid
validator(value) => booleanundefinedSet custom validation
on-blur(event: FocusEvent) => voidundefinedCallback when losing focus
on-clear() => voidundefinedCallback when clicking clear button
on-focus(event: FocusEvent) => voidundefinedCallback when gaining focus
on-update:value(value: number | null) => voidundefinedCallback when component value changes

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