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
v-model.number
will set data to string when input[type="number"] value is empty
#4742
Comments
It is an expected behavior. Vue will try to cast the string to number type, it will return the original string if it fails. And it's also reasonable, or you will always get 0 after you delete the input value. As for your case, it's better to deal with it in the userland. |
|
Vue.js uses |
All right |
Why doesn't the attribute just get removed when its empty? This creates tons of casting errors really... |
@blade254353074 looks like its not just me that doesn't agree that v-model.number should ever be returned as a string, i still hold strongly on thinking that the property should be removed from the object or turned null. |
@kgrosvenor But...now I see Making difference between It's complicated when we only need number type, but it's useful when we need to know if user input or not. You can use |
I guess unexists value for the int typed property should be null instead of empty string. |
Yes a Or maybe there could be a |
@defcc I think this is still worth a conversation. I completely agree that casting to 0 seems incorrect, but what is the use case of this modifier? I think most people would use this thinking now I don't need the extra step of casting the string to an integer because some child component expects and integer not a string. But currently it falls back to a string which means you still need that extra code to ignore it if the cast fails making it significantly less useful. Is there a reason its not cast to undefined or null? |
Thanks, I'll share with team and think it over.
2017-10-19 2:04 GMT+08:00 aldencolerain <notifications@github.com>:
… @defcc <https://github.com/defcc> I think this is still worth a
conversation. I completely agree that casting to 0 seems incorrect, but
what is the use case of this modifier? I think most people would use this
thinking now I don't need the extra step of casting the string to an
integer because some child component expects and integer not a string. But
currently it falls back to a string which means you still need that extra
code to ignore it if the cast fails making it significantly less useful. Is
there a reason its not cast to undefined or null?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#4742 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ACe7jhmbnSN-QctQQ2MVjmqdmimVAADoks5stj2_gaJpZM4Lmznz>
.
|
@defcc @fergaldoyle any update on this? |
I think casting to null would make sense for the number type, i'm used to AngularJS removing it from the object for me, but null would suffice as thats how i initially declare my model so that the text field isn't populated and placeholder text will also show if properties are null. |
I also agree that casting to null would make more sense... |
The workaround I used for numbers being an empty string when cleared out is the following. My .02 is that it should work like this as default, but maybe this will help someone else. (The property is cast as .toString() because of typescript)
|
Would love for this to be null it would make it consistent, this return of string is bound to create problems in projects and no one wants the workaround, but instead a fix and consistent type for empty models and null is best suited for this |
+1 for returning |
Please re-open this.
Given |
@defcc any chance this could get re-opened? |
By using Please reopen this issue or change this behaviour .. Thanks :) |
The value is set to an empty string because that's what the HTML input gives. It still allows people to check if the input is empty by doing |
http://jsfiddle.net/SebastianBlade/krbjt745/
When input value is empty,
num
will turn to string type.Is it a feature? I think number data should be 0 when input value is empty...
The text was updated successfully, but these errors were encountered: