vue-livr

2.0.0 • Public • Published

Vue LIVR

Install

npm i -S livr npm i -S vue-livr

Usage

In your script entry point:

import Vue from 'vue';
import VueLIVR from 'vue-livr';

Vue.use(VueLIVR, {
  extraRules: {}, // Extra rules to be added
  extendedErrors: false, // Patch rules to return extended error codes
  errorHandlers: {}, // Error handler to each error code that LIVR returns, it will run only if extendedErrors = true
  aliasedRules: [], // list of aliasedRules to register
});

Now you are all set to use the plugin.

Basic example

<input :class="{ invalid: errors.hasError('name')}" @blur="validate('name')" v-model="name" />
<span>errors.getError('name')</span>
import VueLIVR from 'vue-livr'
const livrRules = {
  name: ['required', { max_length: 20 }],
};

export default {
  data() {
    return {
      name: '',
    };
  },

  mixins: [VueLIVR.mixin], // this will add a singleton this.$livr instance to your component

  methods: {
    validate(field) {
      const { name } = this;
      this.$livr.validate(livrRules, { name }, field);
    },
  },
};

Array example

<div v-for="(user, index) in users" :key="index">
  <input
    class="listing-units__input"
    v-model="user.name"
    @blur="validate('name', index)"
    :class="{ invalid: errors.hasError('name', index) }"
  />
  <span>{{errors.getError('name', index)}}</span>
</div>

<button @click="validateAll">Validate All</button>
const livrRules = {
  users: [
    'required',
    {
      list_of_objects: [
        {
          name: ['required', { min_length: 1 }],
        },
      ],
    },
  ],
};

export default {
  data() {
    return {
      users: [{ name: '' }, { name: '' }],
    };
  },
  methods: {
    validate(field, index) {
      const fieldName = `users[${index}].${field}[0]`;
      this.$livr.validate(livrRules, this.users, fieldName);
    },
    validateAll() {
      this.$livr.validateAll(livrRules, this.users);
    },
  },
};

Credits

License

MIT

/vue-livr/

    Package Sidebar

    Install

    npm i vue-livr

    Weekly Downloads

    87

    Version

    2.0.0

    License

    MIT

    Unpacked Size

    87.2 kB

    Total Files

    7

    Last publish

    Collaborators

    • andrebragaolxbr
    • everton.segur
    • douglas.marques-olx
    • carlos.mota
    • amintasvrp
    • henrique.monteiro
    • felipemenezesdm
    • pcatalini-olx
    • ansantos
    • bruno.machado.olx
    • carloskasper
    • adriano.hardtke
    • emilyspecht
    • yasuto
    • flavio.pinto
    • reimerf
    • gabriel.barreto
    • mlstellet
    • matheus.olx
    • cmicheletto
    • thamirislopes
    • schneiderolx
    • jullia-silva
    • osmar15
    • andre.mateus
    • fabioadriano3
    • gilvan.reis
    • gislaineamaro
    • manuelneto
    • narda
    • vfaolx
    • helamaboeira
    • masjaque
    • giovana.narciso
    • vinyferay
    • richecr
    • hygo2025
    • joaomellof
    • matheosu
    • br-monteiro
    • andremateusl
    • vinicius.beloti
    • vanessaeich
    • vincenzo-olxbr
    • thalita_olx
    • marcosmeleolx
    • joao.camelo
    • kellybianca
    • yuri_zoel
    • vsabino
    • danieldertoniolx
    • olxbr.marcelo.souza
    • rafael.lara
    • rodrigoodaolxbr
    • esduard
    • acsolxbr
    • robsonkretzmann
    • ricardofermino
    • dr.gutierre
    • diegos.olx
    • jose.junior-ext
    • alexandre.fernandes
    • hanielwolz
    • lorenzocandiago
    • carlosfilipe
    • thiago.pacheco.olxbr
    • yagoazedias
    • thiago.nascimento
    • marcellagutie
    • samuel.braga
    • matheusrsilva
    • brunofsouza
    • roger-toledo
    • fernando.barbosa-ext
    • gustavoresende
    • jeconias.olx
    • igorfonsecaolxbr
    • diozefe
    • joao.zacarkin
    • nathan.ribeiro
    • geoldery
    • daniel_quirino
    • wandersonguimaraes
    • arthus05
    • gabriel-barreto-ext
    • ahcheles
    • girardellibaptista
    • gabrielabergamo
    • lmaiaa
    • nadisonolx
    • luiz.moitinho
    • gustavoaz
    • leocpii
    • marcelo.tdsjr
    • acmon.soares
    • anaclara_
    • geanpeixoto
    • ltiago90
    • wesleymreng7olx
    • jorgevieira
    • sergiohampel
    • pppfs
    • aline.capucho
    • oliveiravinicius
    • jumeneguete
    • rodrigoyo
    • gustavo.armelin
    • notarme
    • mvnsantos
    • amanda-yosh
    • ana-laura
    • pedrolxbr
    • leandro.almeida
    • wendelleloi
    • ricardopdsf
    • almir.junior
    • gabriela.ciriaco
    • marcio.barbosa
    • jeffbraga
    • mibsbalsante
    • luissobral
    • npm-vivareal
    • vivareal-ci
    • lfkondo
    • fernandonito
    • lastikas
    • jhonatagrupozap
    • marcelojunior7
    • bitlucas
    • mauroandremazzola
    • ewertonr
    • fernandoprocy
    • vcovre
    • fsmelo
    • pereirapleandro
    • cabral-ricardo
    • msouza
    • jeffotuka
    • debora.pires
    • bparolini
    • robsonoduarte
    • rogerfernandes
    • giovannicaldeira
    • jmenezes.olxbr
    • daniellemos
    • gabischima
    • marcosgeo