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 Minimum and Maximum Values

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

Set Precision and Step

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

Disabled State

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

Events Examples

Listen to Value Changes

js
const rule = {
    type: "InputNumber",
    field: "quantity",
    title: "Purchase Quantity",
    value: 1,
    props: {
        min: 1,
        max: 100,
    },
    on: {
        change: (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: {
            change: ($inject, value) => {
                // Auto-calculate total price from quantity and unit 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,
            precision: 2,
        },
        inject: true,
        on: {
            change: ($inject, value) => {
                // Auto-calculate total price from quantity and unit 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: TDesign_InputNumber

value :Number

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