-
-
Save parzibyte/1701378620f9d3fd6ff8d976ca537465 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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