hamed-ehtesham / pretty-checkbox-vue

Quickly integrate pretty checkbox components with Vue.js
MIT License
261 stars 31 forks source link

How to stop change of checkbox #15

Closed superern closed 5 years ago

superern commented 5 years ago

I wanted to stop the event change then after only I get response from my ajax query will only change the checkbox.

hamed-ehtesham commented 5 years ago

Hi @superern, Thanks for using this component

How do you change the checkbox now? are you using v-model? could you provide a code which shows what you intend to do?

superern commented 5 years ago

To answer your questions.

I was looking for something like. @change.prevent, but this doesnt seem to work.

Anyhow, I was able to resolve this by returning a false to stop from changing its state then do an ajax request. then i only change state the checkbox on then method via updating the binded data model, in this case: active.

`<p-check class="flex-grow p-switch p-fill" color="success" name="activation" v-model="active" @change="toggle($event)"

{{ toggleLabel }}`

toggle(e){ this.active = !e; axios.get(this.toggleUrl) .then(response => this.active = response.data.active) .catch(error => console.log(error)); },

hamed-ehtesham commented 5 years ago

@change.prevent doesn't work even in default checkbox inputs but @click.prevent does likewise you can use @click.native.prevent in this component

this Codepen shows you an example

superern commented 5 years ago

@hamed-ehtesham thank you so much! this is much cleaner!

hamed-ehtesham commented 5 years ago

You're welcome