Behavior change v-model on input type number cast value to number by defualt
Version
3.2.26
Reproduction link
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
This seem to be the a documented feature for vue 3, which is not vue 2 .
as a workaround for this use case, you can use .trim modifier to get a string
<input type="number" v-model.trim="phoneNumber">
@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..."
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. source
This was working properly in earlier 3.x versions but then the breaking change was introduced (https://github.com/vuejs/core/issues/3813, https://github.com/vuejs/core/blob/main/CHANGELOG.md#320-beta2-2021-07-19)
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.