Am building a Wordpress plugin and am Using Vue Js. I set up a variable that will be set to true on a button click Then another div which is a modal that will remaining hidden with v-if as long as the variable is false. The is also a form in the div modal(pop up)
The problem is that once the value changes, on button pressed, the form submits immediately.
This has been happening but I usually ignore it because there was always a required field which will prevent the form from submitting automatically.
Vue.js Data object
{
selected_to_show : false,
}
The modal div
<div v-if="selected_to_show === true" class='mp-modal'>
<form on:submit.prevent="xhrSubmit()">
<form>
</div>
<button v-on:click="selected_to_show = true"></button>
This works but once the modal opens, the form submits immediately.
Note: There is only two button elements in the form where are all set to type="button"
The target is to prevent the form from submitting automatically when shown
<form>
tag is missing a slash and thesubmit
listener needs to bev-on:
rather thanon:
. However, neither of these explains why the form is submitting. My guess would be that you've got code to submit the form that is running prematurely but you haven't included that code so it's difficult to know exactly. e.g. Could be av-on
that's incorrectly been written as av-bind
. - skirtle