Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created June 2, 2019 16:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/1701378620f9d3fd6ff8d976ca537465 to your computer and use it in GitHub Desktop.
Save parzibyte/1701378620f9d3fd6ff8d976ca537465 to your computer and use it in GitHub Desktop.
Vue.use(VeeValidate, {
classes: true,// Sí queremos que ponga clases automáticamente
// Indicar qué clase poner al input en caso de que sea
// válido o inválido. Usamos Bootstrap 4
classNames: {
valid: "is-valid",
invalid: "is-invalid",
},
// Podría ser blur, change, etcétera. Si está vacío
// entonces se tiene que validar manualmente
events: "change|blur|keyup",
});
VeeValidate.Validator.localize("es");
VeeValidate.Validator.extend('prohibirPalabras', {
getMessage: (campo, argumentos) => {
// argumentos es un arreglo
return "El campo " + campo + " no puede contener las siguientes palabras: " + argumentos.join(" ");
},
validate: (valor, argumentos) => {
return argumentos.every(argumento => !valor.includes(argumento))
},
})
new Vue({
el: "#app",
data: () => ({
usuario: {
nombre: null,
edad: null,
correo: null,
biografia: null,
}
}),
methods: {
intentarEnviar() {
this.$validator.validate()
.then(esValido => {
if (esValido) {
alert("OK, se envía el formulario ;)")
} else {
// Hacer algo aquí
}
});
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment