-
-
Notifications
You must be signed in to change notification settings - Fork 62
Expand file tree
/
Copy pathGenericPassword.vue
More file actions
91 lines (89 loc) · 1.99 KB
/
GenericPassword.vue
File metadata and controls
91 lines (89 loc) · 1.99 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<template>
<v-text-field
v-bind="computedProps"
v-on="$listeners"
@click:append="toggleHide()"
/>
</template>
<script>
import {mdiEye, mdiEyeOff, mdiKey} from '@mdi/js';
import {VTextField} from 'vuetify/lib/components';
export default {
name: 'GenericPassword',
extends: VTextField,
props: {
errorMessages: {
type: [String, Array],
default: () => [],
},
label: {
type: String,
required: false,
},
required: {
type: Boolean,
default: true,
},
standalone: {
type: Boolean,
default: false,
},
new: {
type: Boolean,
required: false,
},
},
data() {
return {
hide_password: true,
};
},
computed: {
computedProps() {
const icon = mdiKey;
const iconToggle = this.hide_password ? mdiEyeOff : mdiEye;
let label = 'Password';
if(!this.required) {
label += ' (Optional)';
}
if(this.new) {
label = 'New ' + label;
}
if(this.label) { // override with custom label
label = this.label;
}
const ruleDefs = {
required: v => !!v || 'Password is required.',
min: v => (v !== undefined && v.length >= 8) || 'Min 8 characters',
};
let rules = []
if(this.required) {
rules.push(ruleDefs.required)
}
if(this.new) {
rules.push(ruleDefs.min)
}
return {
...this.$props,
type: this.hide_password ? 'password' : 'text',
label: label,
autocomplete: this.new ? 'new-password' : '',
prependIcon: this.standalone ? '' : icon,
prependInnerIcon: this.standalone ? icon : '',
appendIcon: iconToggle,
flat: this.standalone,
solo: this.standalone,
outlined: true,
rules: rules,
errorMessages: this.errorMessages,
validateOnInput: true,
}
}
},
methods: {
toggleHide() {
this.hide_password = !this.hide_password;
}
},
};
</script>