Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vuetify checkbox: how to stop the click event?

I tried to have a checkbox with a @click.stop.prevent="myEvent" that shall ask before setting the checkbox to true, but stop and prevent are ignored and the checkbox still gets activated. What might be wrong here?

Here is a fiddle with the described problem: https://jsfiddle.net/ag63f9fm/49/

<v-checkbox @click.native.stop.prevent='ask($event)' :label="`Checkbox 1: ${checkbox1.toString()}`" v-model="checkbox1"></v-checkbox>

the ask method:

ask: function (event) {
    answer = confirm('really')
    console.log('Answer: ' + answer)
    if (!answer) {
        event.stopPropagation()
      event.preventDefault()
    }
    return answer
  }
like image 976
Andy Avatar asked Jun 23 '18 10:06

Andy


People also ask

How do I stop event propagation Vue?

Specifically, we can use stop event modifier. . stop will stop the event propagation.

How do I turn off Vuetify form?

You should bind `disabled` prop to `false` for every control.


2 Answers

Okay, after posting an issue at vuetify I was told to use click.capture instead, but I still don't know why a simple event.stopPropagation() didn't work in the first place.

like image 115
Andy Avatar answered Sep 18 '22 13:09

Andy


this code work fine:

<v-switch  :input-value="checked" @click.native.capture="changeStatus($event)"></v-switch>
methods: {
    changeStatus(event) {
        event.stopPropagation()
    }
}

like image 37
nekooee Avatar answered Sep 21 '22 13:09

nekooee