Final updates. Add v-model and data object.

This commit is contained in:
Bryan Mauger 2023-05-15 11:15:21 -04:00
parent 8859f33bec
commit 6166ce3d9f
2 changed files with 35 additions and 30 deletions

View file

@ -6,7 +6,7 @@
<span v-if="!isRequired" class="fw-normal ms-1">(Optional)</span> <span v-if="!isRequired" class="fw-normal ms-1">(Optional)</span>
</div> </div>
<textarea <textarea
v-model="text" v-model="value"
@keyup="updateCount" @keyup="updateCount"
id="textarea-comments" id="textarea-comments"
class="p-4" class="p-4"
@ -15,10 +15,14 @@
aria-multiline="true" aria-multiline="true"
:aria-required="isRequired"> :aria-required="isRequired">
</textarea> </textarea>
<p tabindex="0" class="caption mt-2 mb-0" id="charactersremaining" :style="{ color: countdownColor }"> <p
tabindex="0"
class="caption mt-2 mb-0"
id="charactersremaining"
:style="{ color: countdownColor }">
{{ remainingCount }}/{{ maxLength }} characters remaining {{ remainingCount }}/{{ maxLength }} characters remaining
</p> </p>
</div> </div>
</template> </template>
<script> <script>
@ -29,15 +33,10 @@ export default {
isRequired: Boolean, isRequired: Boolean,
maxLength: { maxLength: {
type: Number, type: Number,
default: 250 default: 250,
}, },
modelValue: String, modelValue: String,
}, },
data() {
return {
text: ''
};
},
setup(props) { setup(props) {
const inputId = !props.customInputId ? `input-${crypto.randomUUID()}` : props.customInputId; const inputId = !props.customInputId ? `input-${crypto.randomUUID()}` : props.customInputId;
@ -73,19 +72,20 @@ export default {
}, },
}, },
remainingCount() { remainingCount() {
return this.maxLength - this.text.length; return this.maxLength - this.value.length;
}, },
countdownColor() { countdownColor() {
return this.remainingCount <= (this.maxLength * 0.1) ? 'red' : ''; // Chanage text color to red when 10% of max remain
} return this.remainingCount <= this.maxLength * 0.1 ? "red" : "";
},
}, },
methods: { methods: {
updateCount() { updateCount() {
if (this.text.length > this.maxLength) { if (this.value.length > this.maxLength) {
this.text = this.text.slice(0, this.maxLength); this.value = this.value.slice(0, this.maxLength);
}
} }
}, },
},
}; };
</script> </script>

View file

@ -1,5 +1,5 @@
<template> <template>
<textareaquestion cmsWidgetName="TextAreaContentWidget" maxLength="250" /> <textareaquestion v-model="techNotes" cmsWidgetName="TextAreaContentWidget" maxLength="250" />
</template> </template>
<script> <script>
@ -33,6 +33,11 @@ export default {
vm.setCmsContent(resultMap.cmsContent); vm.setCmsContent(resultMap.cmsContent);
}); });
}, },
data() {
return {
techNotes: "",
};
},
computed: { computed: {
textAreaLabelCopy() { textAreaLabelCopy() {
return this.getCmsContent("TextAreaContentWidget", "QuestionText"); return this.getCmsContent("TextAreaContentWidget", "QuestionText");