D
D
DiseaseC2020-11-22 10:58:57
Vue.js
DiseaseC, 2020-11-22 10:58:57

How to submit a form when a checkbox is toggled?

I have a form with a checkbox and a button. When the button is clicked, the form is submitted, but how can I make the form submit when the checkbox is toggled?

Schematically it looks like this:

<form @submit.prevent="submitHandler">
        <div class="switch">
            <input type="checkbox" v-model="isRuLocale" />
            <span class="lever"></span>
        </div>
        <button class="btn" type="submit">
          Обновить
        </button>
      </form>


I'm trying to attach submitHandler to the checkbox itself, but it hasn't worked yet

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2020-11-22
@DiseaseC

export default {
    ...,
    watch: {
        isRuLocale() {
            // submit here
        }
    }
};

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question