0.3.0-beta.2 • Published 6 years ago

vuelidate-forms v0.3.0-beta.2

Weekly downloads
3
License
MIT
Repository
github
Last release
6 years ago

Vuelidate-forms

Combine data object and validation schema in one declaration
Vuelidate docs

Installation

  1. Install vuelidate and vuelidate-forms
npm install vuelidate vuelidate-forms
  1. Import and write Vue.use
import Vue from 'vue'
import Vuelidate from 'vuelidate'
import VuelidateForms from 'vuelidate-forms'

Vue.use(VuelidateForms)
Vue.use(Vuelidate)

Important: you should connect VuelidateForms before Vuelidate.

Usage

Default fields

new Vue({
  forms: {
    test: {
      field: {
        required
      },
      anotherField: {
        required,
        numeric
      }
    }
  }
})

Is equal to

new Vue({
  data: {
    test: {
      field: null,
      anotherField: null
    }
  },
  validations: {
    test: {
      field: { required },
      anotherField: { required, numeric }
    }
  }
})

Fields with default value

new Vue({
  forms: {
    test: {
      field: 'test',
      anotherField: {
        required,
        numeric,
        $value: 5
      }
    }
  }
})

Is equal to

new Vue({
  data: {
    test: {
      field: 'test',
      anotherField: 5
    }
  },
  validations: {
    test: {
      anotherField: {
        required,
        numeric
      }
    }
  }
})

Array validation

new Vue({
  forms: {
    test: {
      list: {
        minLength: minLength(5),
        $each: {
          field: {
            required
          },
          anotherField: {
            required,
            numeric
          }
        }
      }
    }
  }
})

Is equal to

new Vue({
  data: {
    test: {
      list: []
    }
  },
  validations: {
    test: {
      list: {
        minLength: minLength(5),
        $each: {
          field: {
            required
          },
          anotherField: {
            required,
            numeric
          }
        }
      }
    }
  }
})

TODO:

  • Finish plugin
  • Write tests
0.3.0-beta.2

6 years ago

0.3.0-beta.1

6 years ago

0.2.8

7 years ago

0.2.7

7 years ago

0.2.6

7 years ago

0.2.5

7 years ago

0.2.4

7 years ago

0.2.3

7 years ago

0.2.2

7 years ago

0.2.1

7 years ago

0.2.0

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago