Vue.js 2 form component that integrates jQuery Validation and Axios.

Overview

vue-vform

Vue.js 2 form component that integrates jQuery Validation and Axios.

Install

Yarn

yarn add vue-vform --dev

NPM

npm install vue-vform --save-dev

Prerequisites

Usage

Define vform component markup inside your custom component.

For example in your custom-form-component.vue:

<template>

  <vform
    request

    :params="user"
    method="post"
    action="/api/v1/user/add"
    @validate="mySubmitCallback">

    <!-- Your cool stuff -->
    <div class="form-group">
      <label for="txtname">Name</label>
      <input
        name="txtname"
        v-model="user.name"
        required
        data-msg-required="Enter your name"
        type="text" class="form-control">
    </div>

    <div class="form-group">
      <label for="txtemail">E-mail</label>
      <input
        name="txtemail"
        v-model="user.email"
        required
        data-msg-required="Enter your E-mail"
        data-rule-email="true"
        data-msg-email="Enter a valid E-mail address"
        type="text" class="form-control">
    </div>
    <!-- //Your cool stuff -->

    <button type="submit" class="btn btn-primary">Submit</button>

  </vform>

</template>

<script>
  export default {
    data () {
      return {
      	user: {
          name: '',
          email: ''
        }
      }
    },

    methods: {
      /**
       * Callback method when validation is completed.
       */
      mySubmitCallback (promise) {
        promise
          .then(response => response.data)
          .then(data => console.log(data))
          .catch(err => console.log(err.message))
      }
    }
  }
</script>

In your entry app:

const Vue = require('vue')

// jQuery and jQuery Validation
window.$ = window.jQuery = require('jquery')
require('jquery-validation')

// If you want auto form Ajax request (optional)
window.axios = require('axios')

Vue.component('vform', require('vue-vform'))
Vue.component('custom-form-component', require('./components/custom-form-component'))

const app = new Vue({
  el: '#app'
})

Attributes

method (optional)

The request method (POST, PUT, DELETE, PATCH). For dynamic value use v-bind:method="myMethod" or :method="myMethod".

action (optional)

The request URL.

request (optional)

If request (Boolean) attribute is defined vform performs an Ajax Request using Axios and a Promise object is passed to your callback. Make sure that you have Axios before.

params (optional)

The component data binding (usually FormData or plain object {} values) that it will send if request option was setted. (use v-bind:param="mydata" or :param="mydata" property)

accept (optional)

The request Accept header. Default: application/json

Events

@validate

Event when validation is completed. You need to pass the callback defined in your methods: .... A Promise object will be passed if request attribute was defined.

Tip

Laravel v5.4 users: It's necessary to define the Axios common headers in your app.js file. That's is useful when your use Laravel v5.4 and Passport.

axios.defaults.headers.common = {
  'Accept': 'application/json',
  'X-Requested-With': 'XMLHttpRequest',
  'X-CSRF-TOKEN': Laravel.csrfToken
}

License

MIT license

© 2017 José Luis Quintana

You might also like...
Asynchronous form handling and validation for VueJS forms

Asynchronous form handling and validation for VueJS forms

✅  Form Validation for Vue.js
✅ Form Validation for Vue.js

vee-validate is a form validation library for Vue.js that allows you to validate inputs and build better form UIs in a familiar declarative style or u

RawModel.js plugin for Vue.js v2. Form validation has never been easier!

vue-rawmodel RawModel.js plugin for Vue.js v2. Form validation has never been easier! This plugin integrates RawModel.js framework into your Vue.js ap

Form validation for Vue.js 2.2+

vue-form Form validation for Vue.js 2.2+ Install Available through npm as vue-form. import VueForm from 'vue-form'; // or var VueForm = require('vue-f

Vue form components with server-side validation in mind
Vue form components with server-side validation in mind

Vue form components with server side validation in mind About FormVuelar is a set of predefined vue form components which are designed to automaticall

Vue composition function for Form Validation

Form Validation for Vue 3 Vue composition function for Form Validation with async rules. 🌌 Written in TypeScript 🌊 Dynamic Form support 🍂 Light wei

Simple Vue.js form validation library

Simple Vue.js form validation library

Flexible Vue.js form validation directive

Vue form validator A Vue.js directive for form validation Installation npm instal vue-smart-validator --save Getting Started In your scirpt entry poi

Deadly simple form validation for Vue.js

vue-form-validator Deadly simple form validation for Vue.js. Features: Built in data types, including email, number, domain, url, etc. Customizable va

Comments
Releases(v1.0.1)
Owner
Jose Quintana
Software Developer, GNU/Linux/BSD fan & Open Source enthusiast. @rust-lang @golang @docker
Jose Quintana
Vue props validation logic extracted for nested validation in object and arrays.

vue-props-validation Vue props validation logic extracted for nested validation in object and arrays. Install npm install vue-props-validation Usage Y

Rubén Valseca 21 Feb 28, 2022
Sirius Validation - stand-alone JS library for data validation in Node and browsers.

SiriusJS Validation Sirius Validation is stand-alone JS library for data validation in Node and browsers. It offers: 23 build-in validation rules. The

Adrian Miu 1 Mar 24, 2020
Vue data validation rules, very much inspired from Laravel validation

A Vue plugin that provides out-of-the-box data validation rules, very much inspired from Laravel validation system. Installation npm i @primitivesocia

Primitive. 15 Apr 13, 2022
Vue Laravel Validator This plugin handle laravel validation response and simple creating form and posting data

Vue Laravel Validator This plugin handle laravel validation response and simple creating form and posting data. #install npm i vue-laravel-validator -

Metin Seylan 58 Aug 23, 2022
Vue.js form validation plugin that depends on the property not the HTML element on validating with no dependency and respect to Vue reactivity.

Vue.js form validation plugin that depends on the property not the HTML element on validating with no dependency and respect to Vue reactivity.

Mohammed Al-Mahdawi 1 May 7, 2019
Results of small 30 min online coding challenge + small polishing afterwards. Vue JS login form + Express JS login endpoint with CORS middleware and validation of request

Install dependencies: npm -i install Start FE: npm run serve ./frontend/src/main.js Start BE: node ./backend/controller/index.js ToDo: tests docker-co

Oleksii Dubinin 0 Jan 14, 2022
A Vue.js directive for sending data from form and primitive validation

Vue Form Send A Vue.js directive for sending data from form and primitive validation inputs Installation npm i --save-dev vue-form-send import VueForm

Aleksey Pleshkov 3 Apr 13, 2022
Vue Form with Laravel Inspired Validation and Simply Enjoyable Error Messages Api

Vue Form with Laravel Inspired Validation and Simply Enjoyable Error Messages Api. (Form Api, Validator Api, Rules Api, Error Messages Api)

Zak Horton 41 Jul 10, 2022
Another validation form for the Vue. Validates input fields of multiple forms and displays errors

vue-coe-validator ✅ Another validation form for the Vue. Validates input fields of multiple forms and displays errors. Note: without any dependencies.

Vinicius Azevedo 13 Jun 5, 2021
Simple and easy Vue directive for form validation.

Simple and easy Vue.js directive for form validation.

Edward S. Ramos 0 Feb 15, 2021