Newer
Older
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
<template>
<div class="form-group mt-3">
<label class="form-check-label" :for="id">
<span v-if="required">* </span>{{ label }}
</label>
<span v-if="showMaxChars" class="float-end">{{ charLabel }}</span>
<textarea
class="form-control"
:id="id"
:rows="rows"
:required="required"
:value="modelValue"
:maxlength="maxChars"
:disabled="readonly"
@input="updateModel"
/>
</div>
</template>
<script>
/**
* A bootstrap styled textarea input component with a label that shows how many characters were entered.
*/
export default {
name: "FormGroupTextBox",
props: {
label: String,
id: String,
modelValue: String,
rows: Number,
required: Boolean,
readonly: { type: Boolean, default: false },
maxChars: { type: Number, default: -1 },
},
computed: {
showMaxChars: function() {
return this.maxChars >= 0;
},
charCount: function() {
if (this.modelValue) return this.modelValue.trim().length;
else return 0;
},
charLabel: function() {
return this.charCount + "/" + this.maxChars;
},
},
methods: {
updateModel: function($event) {
this.$emit("update:model-value", $event.target.value);
},
},
setup() {},
};
</script>