-
-
Notifications
You must be signed in to change notification settings - Fork 8.4k
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
input type=number doesn't work as intended #3813
Comments
Where is this behaviour described in docs? I can't find anything about it, neither in the guide/api reference nor in the migration guide. |
There is no such thing, Vue2 also does not have this behavior. Maybe the PR I submitted is not needed because of the increased runtime overhead. |
Then maybe |
@jacekkarczmarczyk I found out about this feature by reading the code. I don't think I ever saw it mentioned in docs. I'd say it's rather logical and nice to have, when you bind a A quick blame shows that the code was introduced by @yyx990803 in 3.0.0-alpha.0. The commit comment doesn't provide a lot of background:
Up to you what you want to do about it. Although I said above that it's very convenient to automatically get a number out of |
Since this is an undocumented feature, I will not mark it as a bug, and @edison1105's PR can fix it, let’s wait for @yyx990803 ’s input. |
It would be problematic to have the modifier applied implicitly to v model as there would be no way to turn it off and the string version is more flexible |
A general follow-up question. Can I somehow detect these things build-time? I got bitten of this since this typechecks and emits fine but the string is a number runtime:
But I guess that's the general case, not just for this string/number thing…? |
Version
3.0.11
Reproduction link
https://jsfiddle.net/4ou5ghLd/18/
Steps to reproduce
Vue tries to automatically apply a
number
modifier tov-model
that are set oninput[type=number]
, as can be seen in the code here:https://github.com/vuejs/vue-next/blob/master/packages/runtime-dom/src/directives/vModel.ts#L52
Go to the repro link, try to enter a number in the textbox, you'll see the model contains a
string
, not anumber
What is expected?
v-model
set the ref to a number when used oninput[type=number]
What is actually happening?
v-model
sets the ref to a string, even if the number is validI put a breakpoint inside Vue and it seems like the source line linked above ran before other input properties are set.
The className is still empty and the type is still
text
(the default input type).I recall a change was made on when
v-model
is applied toinput
vs other attributes because of an issue related tomin
andmax
, this could be a regression introduced by that change.The text was updated successfully, but these errors were encountered: