@ezraobiwale/vuravel-validation

3.1.2 • Public • Published

Vuravel Validation

Vue validations, the Laravel way.

This is a wrapper around laravel-style-validation for use with Vue.

Installation

yarn add vuravel-validation
// or
npm install vuravel-validation

Usage

// Vue 3
import { createApp } from 'vue'
import App from './App.vue'
import VuravelValidation from '@ezraobiwale/vuravel-validation'

const app = createApp(App)
const customRules = {}

app.use(VuravelValidation, customRules)

app.mount("#app")

// Vue 2

import Vue from 'vue'
import VuravelValidation from '@ezraobiwale/vuravel-validation'

const customRules = {}
Vue.use(VuravelValidation, customRules)

export default new Vue({
  // ...
})

// App.vue

this.$lsv.validate(...)

All laravel-style-validation functions are available on this.$lsv

See https://github.com/ezra-obiwale/laravel-style-validation#usage for more details.

Custom rule example

Based on this example:

// Create custom rule function
const allowedOptions = (value, { data, field, message, params, rules }) => {
  const isValid = params.includes(value)

  // valiation passes
  if (isValid) {
    return true
  }

  // validation fails and message is disabled
  if (message === false) {
    return false
  }

  // validation failed and custom message exists
  if (message) {
    return message
  }

  // validation failed: return default message
  return 'Allowed parameters include ' + params.join(', ')
}

// Register rule with library
app.use(VuravelValidation, { allowed_options: allowedOptions })

// Use
this.$lsv.validate('yes', 'allowed_options:yes,no,maybe|accepted')

Readme

Keywords

none

Package Sidebar

Install

npm i @ezraobiwale/vuravel-validation

Weekly Downloads

1

Version

3.1.2

License

MIT

Unpacked Size

4.13 kB

Total Files

5

Last publish

Collaborators

  • ezraobiwale