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: "Enter price",
    },
}

Control Button Position

js
const rule = {
    type: "InputNumber",
    field: "quantity",
    title: "Quantity",
    value: 1,
    props: {
        controlsPosition: "right",
        min: 1,
    },
}

Disable Control Buttons

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

Strict Step

js
const rule = {
    type: "InputNumber",
    field: "discount",
    title: "Discount Rate",
    value: 0.1,
    props: {
        step: 0.1,
        stepStrictly: true,
        precision: 1,
        min: 0,
        max: 1,
    },
}

Events Examples

Listen to Value Changes and Focus Events

js
const rule = {
    type: "InputNumber",
    field: "price",
    title: "Product Price",
    value: 0,
    props: {
        min: 0,
        precision: 2,
        placeholder: "Enter price",
    },
    on: {
        change: (value) => {
            console.log('Value changed:', value);
        },
        blur: (event) => {
            console.log('Lost focus:', event);
        },
        focus: (event) => {
            console.log('Gained focus:', event);
        },
    },
}

Calculate Total Price After Value Change

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 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 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: Element_InputNumber

value :Number

Props

Property NameDescriptionTypeDefault Value
minSet minimum value allowed by counternumber-Infinity
maxSet maximum value allowed by counternumberInfinity
stepCounter stepnumber1
stepStrictlyWhether only multiples of step can be enteredbooleanfalse
precisionValue precisionnumber
sizeCounter sizeenumdefault
readonlyNative readonly attribute, whether readonlybooleanfalse
disabledWhether disabledbooleanfalse
controlsWhether to use control buttonsbooleantrue
controlsPositionControl button positionenum
nameEquivalent to native input name attributestring
ariaLabelEquivalent to native input aria-label attributestring
placeholderEquivalent to native input placeholder attributestring
idEquivalent to native input id attributestring
valueOnClearValue displayed when input is clearednumber / null / enum
validateEventWhether to trigger form validationbooleantrue
labelEquivalent to native input aria-label attributestring

Events

NameDescriptionType
changeTriggered when bound value changesFunction
blurTriggered when component Input loses focusFunction
focusTriggered when component Input gains focusFunction

Slots

Slot NameDescription
decrease-iconCustom input decrease button icon
increase-iconCustom input increase button icon
prefixInput header content
suffixInput footer content

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