cleave icon indicating copy to clipboard operation
cleave copied to clipboard

Persistent value after clearing values

Open richbowen opened this issue 7 years ago • 8 comments

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

richbowen avatar Jul 13 '17 22:07 richbowen

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

alevans4 avatar Jul 13 '17 23:07 alevans4

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

richbowen avatar Jul 13 '17 23:07 richbowen

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

heribertusk avatar Sep 28 '17 09:09 heribertusk

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

watch: {
    // ...
    value(val) {
      this.cleave.setRawValue(val)
    }
  }

richbowen avatar Sep 28 '17 16:09 richbowen

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

KyleXie avatar Oct 14 '17 05:10 KyleXie

@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?

heribertusk avatar Oct 22 '17 12:10 heribertusk

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/.

richbowen avatar Oct 23 '17 04:10 richbowen

I have it working with:

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

ezerw avatar Apr 28 '18 07:04 ezerw