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

Behavior change v-model on input type number cast value to number by defualt #5284

Open
eliran-positive opened this issue Jan 18, 2022 · 5 comments
Labels
need guidance The approach/solution in the PR is unclear and requires guidance from maintainer to proceed further. scope: v-model

Comments

@eliran-positive
Copy link

Version

3.2.26

Reproduction link

jsfiddle.net/8vqaotbx/1/

Steps to reproduce

create input element type number
the value cast to number type
On Vue version 2 it not do it by defualt , it is big chage i have big project that expected the value return is string

What is expected?

Mybe can add to core modifier numeric that not cast the value to number.
Or add flag that Vue not do it by defualt

What is actually happening?

v-model cast value of input number to number type


@eliran-positive eliran-positive changed the title By defualt v-model input type number cast to number type Behavior change v-model on input type number cast value to number by defualt Jan 18, 2022
@lidlanca
Copy link
Contributor

This seem to be the a documented feature for vue 3, which is not vue 2 .

image

as a workaround for this use case, you can use .trim modifier to get a string

 <input type="number" v-model.trim="phoneNumber">

@eliran-positive
Copy link
Author

@lidlanca
Thank for the replay and solution it work

But i think that the cast not need to be by default is different behavior

Also the documented in not clear "Vue can automatically convert..." mybe "Vue automatically try to convert..."

@lidlanca
Copy link
Contributor

lidlanca commented Jan 19, 2022

perhaps vue should not have casted by default, keep this issue open, see what core team has to say.

feel free to suggest improvement to the docs if you find the current phrasing confusing
https://github.com/vuejs/docs/issues

also note that the docs will soon be updated to this, which I find even more misleading.
image
source

@jacekkarczmarczyk
Copy link
Contributor

jacekkarczmarczyk commented Jan 19, 2022

This was working properly in earlier 3.x versions but then the breaking change was introduced (#3813, https://github.com/vuejs/core/blob/main/CHANGELOG.md#320-beta2-2021-07-19)

@posva posva added need guidance The approach/solution in the PR is unclear and requires guidance from maintainer to proceed further. scope: v-model labels Feb 9, 2022
@miyukki
Copy link

miyukki commented Feb 9, 2023

I was also affected by this change.

Until now, the length of the string was used to detect that the input filed was empty.
After the change, if the input field is empty it will return a string type and if it is not empty it will return a number type.
In the case of type=number, there was a change to cast to a number as default, but the type is not unified.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
need guidance The approach/solution in the PR is unclear and requires guidance from maintainer to proceed further. scope: v-model
Projects
None yet
Development

No branches or pull requests

5 participants