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

Prevent change #86

Open
galeanofabian opened this issue Sep 19, 2018 · 3 comments
Open

Prevent change #86

galeanofabian opened this issue Sep 19, 2018 · 3 comments
Labels

Comments

@galeanofabian
Copy link

Hi, how can I prevent change in toggle, example, I'm receiving data from database, and when I click in toggle-button I want to execute a method which changes value in database, but I can cancel that operation, problem is when I click on button it changes automatically even canceling operation, what I want is that the button wait if response is true or flase to change. Many thanks

@euvl euvl added the question label Dec 11, 2018
@veebuv
Copy link
Contributor

veebuv commented Mar 27, 2019

toggle(event) {
      if (!this.sync) {
        this.toggled = !this.toggled;
      }
      this.$emit('input', !this.toggled);
      this.$emit('change', {
        value: !this.toggled,
        srcEvent: event,
      });
    }

I forked and made a quick fix like this, yes you end up getting a delay in movement on the toggle - but I can add a tiny loader, which is enh.

Basically states that if the sync is true, listen to the prop value and don't listen to local click events - which is how it should be

@GussRw
Copy link

GussRw commented Apr 3, 2019

You can do those with @click.native

<toggle-button @click.native="yourFunction"/>

and inside your function call preventDefault() like this

yourFunction(event){
    event.preventDefault();
    //TODO
}

@benlind
Copy link

benlind commented Sep 25, 2019

Even simpler:

<toggle-button @click.native.prevent="toggle" />

That also prevents an issue I was seeing where the toggle function was being called twice for a single click.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants