laravel-vue2-validator
Advanced tools
Comparing version 0.0.4 to 0.0.5
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() |
72
index.js
@@ -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", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5482
95