panthro
panthro

Reputation: 24061

Post a form once valid?

Im using vee validate on my inputs, to prevent the form submitting I use:

<form action="/place-to-post-to" @submit.prevent="$validator.validateAll()">

When the form validates, the form does not post. How can I make it post to the action once its valid?

Upvotes: 1

Views: 148

Answers (1)

Bert
Bert

Reputation: 82449

Call validateAll() in a method and on success, submit the form yourself.

<form action="/path/to/action" method="post" @submit.prevent="onSubmit" ref="theForm">

methods:{
    onSubmit(){
      this.$validator.validateAll()
        .then(() =>{
          this.$refs.theForm.submit()
        })
        .catch((error) =>{
          console.log(error)
        })
    }
}

Example.

Upvotes: 1

Related Questions