forked from bootstrap-vue/bootstrap-vue
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathform-state.js
35 lines (34 loc) · 841 Bytes
/
form-state.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/* Form control contextual state class computation
*
* Returned class is either 'is-valid' or 'is-invalid' based on the 'state' prop
* state can be one of five values:
* - true for is-valid
* - false for is-invalid
* - null for no contextual state
*/
import { isBoolean } from '../utils/inspect'
// @vue/component
export default {
props: {
state: {
// Tri-state prop: true, false, null (or undefined)
type: Boolean,
default: null
}
},
computed: {
computedState() {
// If not a boolean, ensure that value is null
return isBoolean(this.state) ? this.state : null
},
stateClass() {
const state = this.computedState
if (state === true) {
return 'is-valid'
} else if (state === false) {
return 'is-invalid'
}
return null
}
}
}