Skip to content
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

[Cleave.js] Extra symbol is added after input has lost focus (if you type more than the mask's limit) #1907

Closed
dmtrbrl opened this issue Oct 24, 2019 · 8 comments

Comments

@dmtrbrl
Copy link

dmtrbrl commented Oct 24, 2019

Overview of the problem

Buefy version: 0.8.6
Vuejs version: 2.6.10
OS/Browser: macOS/Chrome

Description

Extra symbol is added after input has lost focus (if you type more than the mask's limit)

Steps to reproduce

  1. Open example from docs in Codepen
  2. Focus on input
  3. Type more symbols than mask expects
  4. Click somewhere else

The weird thing is that I can reproduce this bug on Codepen and locally.
But on docs page everything works fine.

@jtommy
Copy link
Member

jtommy commented Oct 24, 2019

Probably is something about Vue 2.6.x because the doc is working with Vue 2.5.x

@4KDA
Copy link

4KDA commented Jan 22, 2020

Found a solution?

@service-paradis
Copy link
Collaborator

It seems the problem is not only with Buefy, but with Vue in general (nosir/cleave.js#459, https://forum.vuejs.org/t/custom-directive-not-working-well-with-last-character-cleave-js-value-sync/63990).

@hoquangthaiholy
Copy link

hoquangthaiholy commented Mar 26, 2020

Hi all, I think this can fix this problem temporarily

Vue.directive('cleave', {
    bind(el, binding, vnode) {
        const input = el.querySelector('input')
        input._vCleave = new Cleave(input, binding.value)
        input.addEventListener('input',(e) => {
            vnode.componentInstance.newValue = e.target.value
        })
    },
    unbind(el) {
        const input = el.querySelector('input')
        input._vCleave.destroy()
    }
})

Hope can see Cleave.js fix it in the future

@gutisalex
Copy link

gutisalex commented Apr 2, 2020

Hi all, I think this can fix this problem temporarily

Vue.directive('cleave', {
    bind(el, binding, vnode) {
        const input = el.querySelector('input')
        input._vCleave = new Cleave(input, binding.value)
        input.addEventListener('input',(e) => {
            vnode.componentInstance.newValue = e.target.value
        })
    },
    unbind(el) {
        const input = el.querySelector('input')
        input._vCleave.destroy()
    }
})

Hope can see Cleave.js fix it in the future

Aaaah, I was looking forward to see this kind of fix! But unfortunatly it doesnt really fix this issue because the extra symbol still makes it into the variable. It is just not getting displayed anymore! And that is actually even worse, because the user doesnt know about what is going on, because he doesnt see the extra symbol anymore!

You can check on that when you put a watcher on the variable you are writing to!

@gutisalex
Copy link

gutisalex commented Apr 2, 2020

Just figured a workaround for this... plain simple, just dont use v-model! Use 2 way binding instead like mentioned here...

Example:
In your template:
<b-input v-cleave="mask" :value="someValue" @input.native="onInput" />

In your script:
onInput(event: any) { this.someValue= event.target._vCleave.getFormattedValue(); }

@harlet
Copy link

harlet commented Apr 4, 2020

@stale
Copy link

stale bot commented Oct 2, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Oct 2, 2020
@stale stale bot closed this as completed Oct 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants