vue-bulma / cleave

Vue Cleave component is based on cleave.js for Vue
MIT License
105 stars 17 forks source link

Persistent value after clearing values #11

Open richbowen opened 7 years ago

richbowen commented 7 years ago

When clearing the values of inputs, the cleave components retain the initial value in a variable called initValue. screenshot from 2017-07-13 16-51-05

This shows the value retained by the component on the left where the normal input dialog on the right, after being cleared is empty: screenshot from 2017-07-13 16-52-57

alevans4 commented 7 years ago

@rgb-one you could submit a pull request with the fix we came up with.

richbowen commented 7 years ago

Cool :); gonna go over the code some more so I can understand it better. Thanks @alevans4

heribertusk commented 7 years ago

sorry for bumping this issues, is this problem already solved? because I still can't clear values on input programmaticaly.

richbowen commented 7 years ago

Haven't submitted a pull request. Add this to the watch section of the component:

watch: {
    // ...
    value(val) {
      this.cleave.setRawValue(val)
    }
  }
KyleXie commented 6 years ago

@rgb-one your solution works, how about send a PR for this? Thanks.

heribertusk commented 6 years ago

@rgb-one : your solution works, but i'm using non-standar format for thousand separator. So I change it a bit:

watch: {
    // ...
    value(val) {
     this.cleave.setRawValue(val.replace(/\D/g,''))
    }
  }

Basically I remove all char and only keep number on string. Is this way correct too?

richbowen commented 6 years ago

That seems like it would work, but I think adding such functionality would be better done using "Custom Options" provided by the Cleave package: Here's an example: https://jsfiddle.net/rgb1/LfLbvgrL/4/.

ezerw commented 6 years ago

I have it working with:

<cleave class="form-control" v-model="phone" ref="phone" :options="{...}">
...
clear(){
     this.$refs.phone.cleave.setRawValue(null);
}