Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

laravel-vue2-validator

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

laravel-vue2-validator - npm Package Compare versions

Comparing version 0.0.4 to 0.0.5

74

Errors.js
class Errors {
constructor(){
this.errors = {};
}
constructor () {
this.errors = {}
}
has(key){
return this.errors[key] !== undefined
has (key) {
return this.errors[key] !== undefined
}
first (key) {
if (this.has(key)) {
return this.errors[key][0]
}
}
first(key){
if(this.has(key)){
return this.errors[key][0]
}
get (key) {
if (this.has(key)) {
return this.errors[key]
}
}
get(key){
if(this.has(key)){
return this.errors[key]
all () {
return this.errors
}
fill (values) {
this.errors = values
}
flush () {
this.errors = {}
}
/**
* Clear one or all error fields.
*
* @param {String|undefined} field
*/
clear (field) {
const errors = {}
if (field) {
Object.keys(this.errors).forEach(key => {
if (key !== field) {
errors[key] = this.errors[key]
}
})
}
all(){
return this.errors
}
this.fill(errors)
}
fill(values){
this.errors = values
/**
* Clear errors on keydown.
*
* @param {KeyboardEvent} event
*/
onKeydown (event) {
if (event.target.name) {
this.clear(event.target.name)
}
}
flush() {
this.errors = {};
}
}
export default new Errors()
export default new Errors()

@@ -6,50 +6,50 @@ import Errors from './Errors'

class Validator{
class Validator {
install(Vue){
install (Vue) {
Vue.component('error', ErrorComponent);
Vue.component('error', ErrorComponent);
if(Vue.http){
Vue.http.interceptors.push((request, next) => {
next(response => {
if(response.status === 422){
Errors.fill(response.body)
}
});
});
if (Vue.http) {
Vue.http.interceptors.push((request, next) => {
next(response => {
if (response.status === 422) {
Errors.fill(response.body)
}
});
});
}
if (axios) {
axios.interceptors.response.use((response) => {
return response;
}, (error) => {
if (error.response.status === 422) {
Errors.fill(error.response.data.errors)
}
if (axios) {
axios.interceptors.response.use((response) => {
return response;
}, (error) => {
if (error.response.status === 422) {
Errors.fill(error.response.data.errors)
}
return Promise.reject(error);
});
}
return Promise.reject(error);
});
Vue.mixin({
beforeCreate () {
//errors
this.$options.$errors = {};
Vue.util.defineReactive(this.$options, '$errors', Errors);
if (!this.$options.computed) {
this.$options.computed = {}
}
this.$options.computed["$errors"] = function () {
return this.$options.$errors;
};
},
Vue.mixin({
})
beforeCreate(){
//errors
this.$options.$errors = {};
Vue.util.defineReactive(this.$options, '$errors', Errors);
if(!this.$options.computed){
this.$options.computed = {}
}
this.$options.computed["$errors"] = function() {
return this.$options.$errors;
};
},
}
})
}
}
export default new Validator()
{
"name": "laravel-vue2-validator",
"version": "0.0.4",
"version": "0.0.5",
"description": " Simple package to display error in vue from laravel validation",

@@ -5,0 +5,0 @@ "main": "index.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc