Welcome to mirror list, hosted at ThFree Co, Russian Federation.

InputField.vue « Form « Components « vue « src - github.com/marius-wieschollek/passwords-webextension.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: e902f54e6143b238f4f583b37c03f62f71e7ff2c (plain)
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
92
93
94
95
96
97
98
99
<template>
    <textarea v-if="type === 'textarea'"
           :value="value"
           :placeholder="getPlaceholder"
           :title="getTitle"
           :readonly="readonly"
           filled
           auto-grow
           v-on="listeners"
           @input="handleInput"
           @change="handleChange"/>
    <input v-else
           :type="type"
           :value="value"
           :checked="isChecked"
           :placeholder="getPlaceholder"
           :title="getTitle"
           :readonly="readonly"
           v-on="listeners"
           @input="handleInput"
           @change="handleChange"/>
</template>

<script>
    import LocalisationService from '@js/Services/LocalisationService';

    export default {

        props: {
            type       : {
                type   : String,
                default: 'text'
            },
            value      : {
                type   : [String, Number, Boolean],
                default: null
            },
            checked    : {
                type   : Boolean,
                default: null
            },
            placeholder: {
                type   : String,
                default: ''
            },
            title      : {
                type   : String,
                default: ''
            },
            readonly : {
                type   : Boolean,
                default: false
            }
        },

        computed: {
            getPlaceholder() {
                if(this.placeholder.length === 0) return;

                return LocalisationService.translate(this.placeholder);
            },
            getTitle() {
                if(this.title.length === 0) return;

                return LocalisationService.translate(this.title);
            },
            isChecked() {
                if(this.type !== 'checkbox' && this.type !== 'radio') return undefined;

                return this.checked || this.value;
            },
            listeners() {
                let listeners = {};

                for(let key in this.$listeners) {
                    if(this.$listeners.hasOwnProperty(key) && key !== 'input' && key !== 'change') {
                        listeners[key] = this.$listeners[key];
                    }
                }

                return listeners;
            }
        },

        methods: {
            handleInput($event) {
                if(this.type !== 'checkbox' && this.type !== 'radio') {
                    this.$emit('input', $event.target.value);
                }
            },
            handleChange($event) {
                if(this.type === 'checkbox' || this.type === 'radio') {
                    this.$emit('change', $event.target.checked);
                    this.$emit('input', $event.target.checked);
                }
            }
        }
    };
</script>