Skip to content

Commit

Permalink
Merge branch 'developernaren-vue-integration-readme'
Browse files Browse the repository at this point in the history
  • Loading branch information
nosir committed Mar 1, 2020
2 parents e9d55ba + 925d488 commit d9a881b
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,10 @@ Then easily you can apply `cleave` directive to `input` field:

More usage in documentation: [Angular directive usage](https://github.com/nosir/cleave.js/blob/master/doc/angularjs-directive-usage.md)

## Use in VueJs
While this package does not have an official support for use in VueJs. This can be done in few simple steps.
Please check [here](https://github.com/nosir/cleave.js/blob/master/doc/vue.md)

## jQuery fn usage
Please check [here](https://github.com/nosir/cleave.js/issues/341)

Expand Down
59 changes: 59 additions & 0 deletions doc/vue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Use in VueJs
Please check [here](https://github.com/nosir/cleave.js/issues/341)

While this package does not have an official support for use in VueJs. This can be done in few simple steps.

## To use globally

```js
import Vue from 'vue'
import Cleave from 'cleave.js';

Vue.directive('cleave', {
inserted: (el, binding) => {
el.cleave = new Cleave(el, binding.value || {})
},
update: (el) => {
const event = new Event('input', {bubbles: true});
setTimeout(function () {
el.value = el.cleave.properties.result
el.dispatchEvent(event)
}, 100);
}
})
```

## To use as a local local directive

```js
import Cleave from 'cleave.js';
export default {

...
directives: {
cleave: {
inserted: (el, binding) => {
el.cleave = new Cleave(el, binding.value || {})
},
update: (el) => {
const event = new Event('input', {bubbles: true});
setTimeout(function () {
el.value = el.cleave.properties.result
el.dispatchEvent(event)
}, 100);
}
}
}
...
}
```

And use it in your HTML like

```html
<input v-model="ccNumber" class="input-element" v-cleave="{creditCard: true, onCreditCardTypeChanged : cardChanged}">
<input name="text" v-model="ccMonth" v-cleave="{date: true,datePattern: ['m']}">
<input type="number" v-model="ccv" v-cleave="{numeral: true,numeralPositiveOnly: true,numeralIntegerScale: 3}">
```

Here is a [codesandbox](https://codesandbox.io/s/cleave-js-vue-integration-qmw28)

0 comments on commit d9a881b

Please sign in to comment.