question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

bug: type="number" is not repected to v-model. String instead of number despite ref<number>

See original GitHub issue

Prerequisites

Ionic Framework Version

  • v4.x
  • v5.x
  • v6.x
  • Nightly

Current Behavior

The string is returned to the model instead of the number.

Expected Behavior

The nnumber is returned to the model if type=“number”.

Steps to Reproduce

<template>
<ion-input type="number" v-model="itemQty" inputmode="numeric"></ion-input>
</template>

<script lang="ts">
export default defineComponent({
setup() {
const qty = ref<number>(1);
watch(qty, (value) => {
      console.log(typeof value)
    })

return {
qty
}
}
})
</script>

Code Reproduction URL

No response

Ionic Info

Ionic:

Ionic CLI : 6.18.1 (/usr/local/lib/node_modules/@ionic/cli) Ionic Framework : @ionic/vue 6.1.0

Capacitor:

Capacitor CLI : 3.4.0 @capacitor/android : 3.4.0 @capacitor/core : 3.4.3 @capacitor/ios : 3.4.0

Utility:

cordova-res : 0.15.4 native-run : 1.5.0

System:

NodeJS : v14.17.4 (/usr/local/bin/node) npm : 8.7.0 OS : macOS Monterey

Additional Information

I have found similar issues on Github but all of them related to Angular and not Vue, also they are 3-4 years old. The current workaround will be to use watchers and parseFloat the value, however i do not see it is a great workaround as the model updated twice, and the types also not respected so the result could be unexpected

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
z0lo13commented, Apr 25, 2022

Sure I will create it.

Thank you On Apr 25, 2022, 4:10 PM -0400, Liam DeBeasi @.***>, wrote:

I am unable to reproduce this using the code snippet provided which is why I requested a GitHub repo. Can you please provide a minimal GitHub repo that I can use to verify this behavior? — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

0reactions
amandaejohnstoncommented, May 9, 2022

Thanks for the issue! This issue is being closed due to the lack of a code reproduction. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.

Read more comments on GitHub >

github_iconTop Results From Across the Web

v-model.number will set data to string when input[type ...
It is an expected behavior. Vue will try to cast the string to number type, it will return the original string if it...
Read more >
vue.js - v-text-field returns string after typing even though it has ...
Question 1) as soon as i change the number or type in it, it throws number value correctly, but its type is String...
Read more >
Form Input Bindings - Vue.js
v-model supports value bindings of non-string values as well! In the above example, when the option is selected, selected will be set to...
Read more >
What you should know about Vue v-model - LearnVue
Often, our inputs will automatically type the input as a String – even if we declare our input to be type number.
Read more >
Using v-model for Two-Way Binding in Vue.js | DigitalOcean
By default, v-model is evaluated every time the input event is fired (ie. · If you'd like to cast user input to a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found