Skip to content

[Bug Report]inputNumber限制输入位数,失去焦点之后会多赋值一位 #374

Open
@loveCoderJ

Description

@loveCoderJ

Activity

dosubot

dosubot commented on Jun 27, 2024

@dosubot

To resolve the issue where an extra digit is added to the inputNumber component after the input loses focus when a limit on the number of digits is set, you need to ensure that the value is properly formatted according to the specified precision when the input loses focus. This can be done by modifying the blur method to format the value correctly.

Here is the relevant part of the code with the necessary changes:

methods: {
    // ... other methods
    blur () {
        this.focused = false;
        this.$emit('on-blur');
        if (!findComponentUpward(this, ['DatePicker', 'TimePicker', 'Cascader', 'Search'])) {
            this.handleFormItemChange('blur', this.currentValue);
        }
        // Ensure the value is formatted according to the precision
        if (this.precision !== undefined && this.currentValue !== null) {
            this.currentValue = Number(this.currentValue).toFixed(this.precision);
            this.$emit('update:modelValue', this.currentValue);
        }
    },
    // ... other methods
}

Additionally, ensure that the precision property is correctly set in the InputNumber component. According to the types/input-number.d.ts file from ViewUIPlus, the precision property is used to define the number of decimal places:

export declare const InputNumber: DefineComponent<{
    // ... other properties

    /**
     * 数值精度
     */
    precision?: number;

    // ... other properties
}>

This change ensures that when the input loses focus, the value is formatted to the specified precision, preventing any extra digits from being added [1][2].

To continue talking to Dosu, mention @dosu.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @loveCoderJ

        Issue actions

          [Bug Report]inputNumber限制输入位数,失去焦点之后会多赋值一位 · Issue #374 · view-design/ViewUIPlus