3.1.2 • Published 2 years ago

@ezraobiwale/vuravel-validation v3.1.2

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

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')
3.1.2

2 years ago

3.1.1

2 years ago

3.1.0

2 years ago

3.0.7

2 years ago

3.0.6

2 years ago

3.0.5

2 years ago

3.0.4

2 years ago

3.0.3

2 years ago

3.0.2

2 years ago

3.0.1

2 years ago

3.0.0

2 years ago

2.0.0

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago