Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
loveCoderJ opened this issue Jun 27, 2024 · 1 comment
Labels
Bug Something isn't working

Comments

@loveCoderJ
Copy link

No description provided.

@dosubot dosubot bot added the Bug Something isn't working label Jun 27, 2024
Copy link

dosubot bot commented Jun 27, 2024

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
Labels
Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant