cretueusebiu / vform

Handle Laravel-Vue forms and validation with ease.
https://vform.vercel.app
MIT License
607 stars 120 forks source link

Submit form with a submit button outside the form #21

Closed jay7793 closed 6 years ago

jay7793 commented 6 years ago

Template code.

<form id="answerForm" @submit.prevent="createAnswer" @keydown="form.onKeydown($event)">
   <input type="text" name="title" v-model="form.content">
</form>

<v-button type="primary" @click.prevent="answerSubmit" class="btn-sm" :loading="form.busy">Submit</v-button>

I created answerSubmit() method inside Vue.js for submit form. But does not work.

answerSubmit () {
   document.getElementById('answerForm').submit()
},

PS. I'm using https://github.com/cretueusebiu/laravel-nuxt starter

cretueusebiu commented 6 years ago

Why don't you just call createAnswer when you click on the submit button ?

But if you really want to trigger the form use dispatchEvent: https://codepen.io/anon/pen/PQqGVg?editors=1010