2021-09-07 02:24:02 +02:00
|
|
|
<template>
|
|
|
|
<div class="input-group mb-3">
|
2021-09-07 10:46:42 +02:00
|
|
|
<!--
|
|
|
|
Hack - Disable Chrome save password
|
|
|
|
readonly + onfocus
|
|
|
|
https://stackoverflow.com/questions/41217019/how-to-prevent-a-browser-from-storing-passwords
|
|
|
|
-->
|
|
|
|
<input
|
|
|
|
v-model="model"
|
|
|
|
:type="visibility"
|
|
|
|
class="form-control"
|
|
|
|
:placeholder="placeholder"
|
|
|
|
:maxlength="maxlength"
|
|
|
|
:autocomplete="autocomplete"
|
|
|
|
:required="required"
|
2021-09-07 11:06:33 +02:00
|
|
|
:readonly="isReadOnly"
|
|
|
|
@focus="removeReadOnly"
|
2021-09-07 10:46:42 +02:00
|
|
|
>
|
|
|
|
|
2021-09-07 02:24:02 +02:00
|
|
|
<a v-if="visibility == 'password'" class="btn btn-outline-primary" @click="showInput()">
|
|
|
|
<font-awesome-icon icon="eye" />
|
|
|
|
</a>
|
|
|
|
<a v-if="visibility == 'text'" class="btn btn-outline-primary" @click="hideInput()">
|
|
|
|
<font-awesome-icon icon="eye-slash" />
|
|
|
|
</a>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
export default {
|
|
|
|
props: {
|
|
|
|
modelValue: {
|
|
|
|
type: String,
|
|
|
|
default: ""
|
|
|
|
},
|
|
|
|
placeholder: {
|
|
|
|
type: String,
|
|
|
|
default: ""
|
|
|
|
},
|
|
|
|
maxlength: {
|
|
|
|
type: Number,
|
|
|
|
default: 255
|
|
|
|
},
|
|
|
|
autocomplete: {
|
|
|
|
type: Boolean,
|
|
|
|
},
|
|
|
|
required: {
|
|
|
|
type: Boolean
|
|
|
|
},
|
2021-09-07 11:06:33 +02:00
|
|
|
readonly: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false,
|
|
|
|
},
|
2021-09-07 02:24:02 +02:00
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
2021-09-07 11:06:33 +02:00
|
|
|
visibility: "password",
|
|
|
|
readOnlyValue: false,
|
2021-09-07 02:24:02 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
model: {
|
|
|
|
get() {
|
|
|
|
return this.modelValue
|
|
|
|
},
|
|
|
|
set(value) {
|
2021-09-07 10:46:42 +02:00
|
|
|
this.$emit("update:modelValue", value)
|
2021-09-07 02:24:02 +02:00
|
|
|
}
|
2021-09-07 11:06:33 +02:00
|
|
|
},
|
|
|
|
isReadOnly() {
|
|
|
|
// Actually readonly from prop
|
|
|
|
if (this.readonly) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Hack - Disable Chrome save password
|
|
|
|
return this.readOnlyValue;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
created() {
|
|
|
|
// Hack - Disable Chrome save password
|
|
|
|
if (this.autocomplete) {
|
|
|
|
this.readOnlyValue = "readonly";
|
2021-09-07 02:24:02 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
showInput() {
|
|
|
|
this.visibility = "text";
|
|
|
|
},
|
|
|
|
hideInput() {
|
|
|
|
this.visibility = "password";
|
2021-09-07 11:06:33 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
// Hack - Disable Chrome save password
|
|
|
|
removeReadOnly() {
|
|
|
|
if (this.autocomplete) {
|
|
|
|
this.readOnlyValue = false;
|
|
|
|
}
|
2021-09-07 02:24:02 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|