Skip to content

feat(VNumberInput): extract number from pasted text #21263

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

J-Sek
Copy link
Contributor

@J-Sek J-Sek commented Apr 14, 2025

Description

Currently user action is completely ignored if even one character causes onBeforeinput to bail. A nicer UX would be to extract the digits to support copy/pasting from spreadsheets or PDFs.

I would prefer to merge it to master as it can be considered a bug by many developers at this point.

Markup:

<template>
  <v-container>
    <v-row>
      <v-col cols="6" lg="3">
        <h5>(default precision="0" max="200")</h5>
        <v-number-input v-model="example1" clearable hide-details="auto" :max="200" />
        <code class="d-block pt-3">value: {{ example1 ?? 'null' }}</code>
        <input class="border-md pa-2 mt-2" type="number" v-model="example1" />
      </v-col>
      <v-col cols="6" lg="3">
        <h5>(precision="1")</h5>
        <v-number-input v-model="example2" :precision="1" hide-details="auto"></v-number-input>
        <code class="d-block pt-3">value: {{ example2 ?? 'null' }}</code>
        <input class="border-md pa-2 mt-2" type="number" v-model="example2" />
      </v-col>
      <v-col cols="6" lg="3">
        <h5>(precision="5")</h5>
        <v-number-input v-model="example3" :precision="5" hide-details="auto"></v-number-input>
        <code class="d-block pt-3">value: {{ example3 ?? 'null' }}</code>
        <input class="border-md pa-2 mt-2" type="number" v-model="example3" />
      </v-col>
      <v-col cols="6" lg="3">
        <h5>(precision="3" min='4' max='120') w/ initial null</h5>
        <v-number-input v-model="example4" :precision="3" hide-details="auto" :min='4' :max='120'></v-number-input>
        <code class="d-block pt-3">value: {{ example4 ?? 'null' }}</code>
        <input class="border-md pa-2 mt-2" type="number" v-model="example4" />
      </v-col>
    </v-row>
    <v-alert class="mt-12">
      Values to copy/paste:
      <ul>
        <li><v-kdb>421.00</v-kdb></li>
        <li><v-kdb>23 567.20</v-kdb></li>
        <li><v-kdb>8,999.99</v-kdb></li>
        <li><v-kdb>$ 120.95</v-kdb></li>
      </ul>
    </v-alert>
  </v-container>
</template>

<script setup>
  import { ref } from 'vue'
  const example1 = ref(150.5)
  const example2 = ref(25.5)
  const example3 = ref(0.052)
  const example4 = ref(null)
</script>

@J-Sek J-Sek self-assigned this Apr 14, 2025
@J-Sek J-Sek requested a review from yuwu9145 April 14, 2025 20:31
@J-Sek J-Sek force-pushed the feat/vnumberinput-pasting branch from 9752c4a to 38a8f6a Compare April 14, 2025 20:38
@J-Sek
Copy link
Contributor Author

J-Sek commented Apr 14, 2025

In case anyone runs the tests right from the VSCode... it fails when running only the new tests, but succeeds when running whole file. It may have something to do with it.each and some internals of vitest.explorer extension. I wish to be the only person that wasted time on it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant