0

Before I started using Vue I had a simple form that would update 1 value on 1 column @ 1 request at a time. Now I am using Vue and my form has a new 'middle' button that is being used to build up an array of items to submit 1 request to update multiple columns dynamically.

Problem is now that prevent default is enabled, my original form submission no longer works and I need to either submit the request with Vue or is there a way to re-enable default action on a button? This would be great.

<form @submit.prevent="newbutton">

// new button
<button @click="newbutton"></button>

// original button
<button @click="submit" :id="{{ $element->id }}></button> // @submit.enableDefault ??

1 Answer 1

1

The prevent is just a helper method on the @submit. To allow this variance you will need to move the logic into your newbutton method

// in template remove prevent
<form @submit="newbutton" action="/where-this-should-post">

// in script move logic to your newbutton method
methods {
  newbutton(event) {
    if (formNotValid) {
      event.preventDefault()
    }
  }
}
Sign up to request clarification or add additional context in comments.

9 Comments

Interesting! How do you test for formNotValid? Thanks for the help!
No need to test for formNotValid, just fired event.preventDefault(); in the middle button and took out @submit.prevent and it works nearly as expected. Problem now is binding the vue data to form submission
It can be a computed property or you can create a function and call that. It will look at all the data in your form and make sure it is OK to send it along.
Also is not required to have that is just easier in spas to knock that out on front end
Ok, that sounds like a separate issue where you are not settings the data using vm.set ([] is not reactive in vue). You should first see if submitting this works with moving event.preventDefault as described above by just posting up something like string 'foo' using axios. If the data gets there then create a new question with the new issue, will help others in the future. Also always best to add a jsfiddle with example.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.