Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 500028e

Browse files
First commit
0 parents commit 500028e

File tree

5 files changed

+131
-0
lines changed

5 files changed

+131
-0
lines changed

‎ErrorComponent.vue‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<template>
2+
<div v-if="$errors.has(input)" class="txt-darkRed">
3+
{{ $errors.first(input) }}
4+
</div>
5+
</template>
6+
<script>
7+
8+
export default {
9+
10+
props: ['input'],
11+
12+
data(){
13+
return {}
14+
},
15+
16+
methods: {},
17+
18+
computed: {},
19+
20+
watch: {},
21+
22+
mounted(){
23+
24+
}
25+
}
26+
27+
</script>

‎Errors.js‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
class Errors {
2+
3+
constructor(){
4+
this.errors = {};
5+
}
6+
7+
has(key){
8+
return this.errors[key] !== undefined
9+
}
10+
11+
first(key){
12+
if(this.has(key)){
13+
return this.errors[key][0]
14+
}
15+
}
16+
17+
get(key){
18+
if(this.has(key)){
19+
return this.errors[key]
20+
}
21+
}
22+
23+
all(){
24+
return this.errors
25+
}
26+
27+
fill(values){
28+
this.errors = values
29+
}
30+
31+
flush() {
32+
this.errors = {};
33+
}
34+
35+
}
36+
37+
export default new Errors()

‎README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

‎index.js‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import Errors from './Errors'
2+
import ErrorComponent from './ErrorComponent.vue'
3+
4+
5+
class Validator{
6+
7+
install(Vue){
8+
9+
Vue.component('error', ErrorComponent);
10+
11+
if(Vue.http){
12+
Vue.http.interceptors.push((request, next) => {
13+
next(response => {
14+
if(response.status === 422){
15+
Errors.fill(response.body)
16+
}
17+
});
18+
});
19+
}
20+
21+
Vue.mixin({
22+
23+
beforeCreate(){
24+
//errors
25+
this.$options.$errors = {};
26+
Vue.util.defineReactive(this.$options, '$errors', Errors);
27+
if(!this.$options.computed){
28+
this.$options.computed = {}
29+
}
30+
this.$options.computed["$errors"] = function() {
31+
return this.$options.$errors;
32+
};
33+
},
34+
35+
})
36+
37+
}
38+
39+
}
40+
41+
export default new Validator()

‎package.json‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"name": "laravel-vue-validator",
3+
"version": "1.0.0",
4+
"description": " Simple package to display error in vue from laravel validation",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"repository": {
10+
"type": "git",
11+
"url": "git+https://github.com/val-bubbleflat/laravel-vue-validator.git"
12+
},
13+
"keywords": [
14+
"laravel",
15+
"vue",
16+
"validate",
17+
"validator"
18+
],
19+
"author": "val bubbleflat <valentin@bubbleflat.com> (bubbleflat.com)",
20+
"license": "MIT",
21+
"bugs": {
22+
"url": "https://github.com/val-bubbleflat/laravel-vue-validator/issues"
23+
},
24+
"homepage": "https://github.com/val-bubbleflat/laravel-vue-validator#readme"
25+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /