Skip to content
This repository was archived by the owner on Nov 30, 2020. It is now read-only.

Commit 11fae05

Browse files
committed
add FormInput validation states
1 parent 98c8457 commit 11fae05

File tree

4 files changed

+30
-5
lines changed

4 files changed

+30
-5
lines changed

example/src/components/FormsPage.vue

+5-4
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,14 @@
3535
</form-group>
3636
<form-group>
3737
<form-label>Valid State</form-label>
38-
<form-input placeholder="Valid State.."/>
39-
<form-input class="mt-3" placeholder="Valid State.."/>
38+
<form-input valid placeholder="Valid State.."/>
39+
<form-input tick class="mt-3" value="Valid state"/>
4040
</form-group>
4141
<form-group>
4242
<form-label>Invalid State</form-label>
43-
<form-input placeholder="Invalid State.."/>
44-
<form-input class="mt-3" placeholder="Invalid State.."/>
43+
<form-input invalid placeholder="Invalid State.."/>
44+
<form-invalid-feedback feedback="Invalid feedback"/>
45+
<form-input cross class="mt-3" value="Invalid state"/>
4546
</form-group>
4647
<form-group>
4748
<form-label>Country</form-label>

src/components/Form/FormInput.vue

+16-1
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,33 @@
11
<template>
2-
<input class="form-control" v-model="internalValue" @input="onInput" >
2+
<input class="form-control" :class="className" v-model="internalValue" @input="onInput" >
33
</template>
44

55
<script>
66
export default {
77
name: "form-input",
88
props: {
99
value: {},
10+
invalid: { default: false, type: Boolean },
11+
valid: { default: false, type: Boolean },
12+
tick: {default: false, type: Boolean},
13+
cross: {default: false, type: Boolean}
1014
},
1115
1216
data: () => ({
1317
internalValue: null
1418
}),
1519
20+
computed: {
21+
className () {
22+
const className = {}
23+
className['is-valid'] = this.valid
24+
className['state-valid'] = this.tick
25+
className['is-invalid'] = this.invalid
26+
className['state-invalid'] = this.cross
27+
return className
28+
}
29+
},
30+
1631
methods: {
1732
onInput() {
1833
this.$emit('input', this.internalValue)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export default {
2+
name: 'form-invalid-feedback',
3+
props: {
4+
feedback: {default: '', type: String}
5+
},
6+
template: `<div class="invalid-feedback"><slot>{{ feedback }}</slot></div>`
7+
}

src/components/Form/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import FormGroup from './FormGroup'
22
import FormInput from './FormInput'
3+
import FormInvalidFeedback from './FormInvalidFeedback'
34
import FormLabel from './FormLabel'
45
import FormStaticText from './FormStaticText'
56
import FormTextarea from './FormTextarea'
67

78
export {
89
FormGroup,
910
FormInput,
11+
FormInvalidFeedback,
1012
FormLabel,
1113
FormStaticText,
1214
FormTextarea

0 commit comments

Comments
 (0)