Home

Awesome

New version!!!

This branch has reached its EOL.

You can get the new improved, revamped and powerful version at vue-daval.

The basics are the same but now it has more options and much more improvements. Here is a small list of them:

Because of all new features and easier reach, I renamed the component to vue-daval (Vue Data Validation)

So this version will not be updated anymore and you have to switch to the new branch. But do not worry, update will be easy and straight as the simplicity is maintained and even increased.

Overview

This is a Vue data validator, developed with the lack of other valiadtors in mind.

Demo

You can view a demo here.

Features

FeatureDescription
Template agnosticNo matter what template library you use, this validator will simply work
SimplicityFocused in developer easiness to save time and headaches
Reactivity persistanceWhen data is loaded from server you can set it without worring, it will restore the watchers
Data treeIf you have nested data objects to validate, this mixin will deal with it without trouble
PerformanceIf a validation in value fails will not run the rest of validations for the value, reducing time and processing considerably
PromisesWill detect if the returned validation is a promise and handle properly without need of external packages
Real timeI have found that in some validators the results are showed in the next tick. This mixin forces the render to be updated once the validations are finished so no delays on result are produced
Async validationsIf a typing is being validated against a resource it will control the times in order to ensure that the last one is the validation that prevails against the previuos
RevalidationsIt controls whether a validation is performed or not, so if the value does not change it will not be validated again, saving time and processing
Dependencies freeIts just ~25KB minified and served as mixin just with vue as dependency in order to reduce the processing, time and load. It is set out to accomplish most of the use cases so it is adapted to common use needs
Community openFeel free to contribute or bring suggestions, any improvement will be at least taken in mind, discussed and accepted if reasonable, just keep the the previous rules in mind

Quickstart

npm install --save vuejs-model-validator
<form @submit.prevent="validateLogin" class="login">
   <input name="email" v-model="login.email">
   <input type="password" name="password" v-model="login.password">

   <button type="submit">Login</button>
</form>

<form @submit.prevent="validateRegister" class="register">
   <input name="alias" v-model="register.alias">
   <input type="email" name="email" v-model="register.email">
   <input type="password" name="password" v-model="register.password">
   <input type="password" name="passwordRepeat" v-model="register.passwordRepeat">

   <button type="submit">Register</button>
</form>
import vmv from 'vuejs-model-validator';

export default {
   mixins: [ vmv ],

   data: () => ({
      login: {
         email: null,
         password: null
      },

      register: {
         alias: null,
         email: null,
         password: null,
         passwordRepeat: null
      }
   }),

   validations: {
      login: {
         email: { required: true, type: 'email' },
         password: { required: true, minlen: 5 },
      },

      register: {
         alias: { required: true, minlen: 5, checkAlias: (vm, alias) => {
            return vm.$http.post('/users/check/alias', { alias: alias });
         }},
         email: { required: true, type: 'email', checkEmail: (vm, email) => {
            return vm.$http.post('/users/check/email', { email: email });
         }},
         password: { required: true, minlen: 5 },
         passwordRepeat: { required: true, equals: 'register.password' }
      }
   },

   methods: {
      validateLogin() {
         this.$vmv.$validate('login', () => {
            this.$http.post('/users/login', this.login);

         }, () => {
            alert('Error in login form');
         });
      },

      validateRegister() {
         this.$vmv.$validate('register', () => {
            this.$http.post('/users/register', this.register);

         }, () => {
            alert('Error in register form');
         });
      }
   }
}

Performance

Weight is just 25KB so is pretty light and is tweaked to be as fast as possible.

Included validations

Troubleshooting

If you find yourself running into issues during installation or running the validator, please check our Wiki. If still needs help open an issue. We would be happy to discuss how they can be solved.

Documentation

You can view the full documentation at the project's Wiki with examples and detailed information.

Inspiration

This slider was inspired by async-validator.

Contributing

Contributions, questions and comments are all welcome and encouraged.