Final updates. Add v-model and data object.
This commit is contained in:
parent
8859f33bec
commit
6166ce3d9f
2 changed files with 35 additions and 30 deletions
|
|
@ -6,19 +6,23 @@
|
|||
<span v-if="!isRequired" class="fw-normal ms-1">(Optional)</span>
|
||||
</div>
|
||||
<textarea
|
||||
v-model="text"
|
||||
@keyup="updateCount"
|
||||
id="textarea-comments"
|
||||
class="p-4"
|
||||
:maxlength="maxLength"
|
||||
role="textbox"
|
||||
aria-multiline="true"
|
||||
:aria-required="isRequired">
|
||||
</textarea>
|
||||
<p tabindex="0" class="caption mt-2 mb-0" id="charactersremaining" :style="{ color: countdownColor }">
|
||||
{{ remainingCount }}/{{ maxLength }} characters remaining
|
||||
</p>
|
||||
</div>
|
||||
v-model="value"
|
||||
@keyup="updateCount"
|
||||
id="textarea-comments"
|
||||
class="p-4"
|
||||
:maxlength="maxLength"
|
||||
role="textbox"
|
||||
aria-multiline="true"
|
||||
:aria-required="isRequired">
|
||||
</textarea>
|
||||
<p
|
||||
tabindex="0"
|
||||
class="caption mt-2 mb-0"
|
||||
id="charactersremaining"
|
||||
:style="{ color: countdownColor }">
|
||||
{{ remainingCount }}/{{ maxLength }} characters remaining
|
||||
</p>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
|
|
@ -29,15 +33,10 @@ export default {
|
|||
isRequired: Boolean,
|
||||
maxLength: {
|
||||
type: Number,
|
||||
default: 250
|
||||
default: 250,
|
||||
},
|
||||
modelValue: String,
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
text: ''
|
||||
};
|
||||
},
|
||||
setup(props) {
|
||||
const inputId = !props.customInputId ? `input-${crypto.randomUUID()}` : props.customInputId;
|
||||
|
||||
|
|
@ -47,11 +46,11 @@ export default {
|
|||
|
||||
switch (typeof modelValue) {
|
||||
case "number":
|
||||
initialValue = modelValue;
|
||||
break;
|
||||
initialValue = modelValue;
|
||||
break;
|
||||
default:
|
||||
initialValue = modelValue && modelValue.length > 0 ? modelValue : "";
|
||||
break;
|
||||
initialValue = modelValue && modelValue.length > 0 ? modelValue : "";
|
||||
break;
|
||||
}
|
||||
|
||||
const fieldOptions = {
|
||||
|
|
@ -73,18 +72,19 @@ export default {
|
|||
},
|
||||
},
|
||||
remainingCount() {
|
||||
return this.maxLength - this.text.length;
|
||||
return this.maxLength - this.value.length;
|
||||
},
|
||||
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: {
|
||||
updateCount() {
|
||||
if (this.text.length > this.maxLength) {
|
||||
this.text = this.text.slice(0, this.maxLength);
|
||||
if (this.value.length > this.maxLength) {
|
||||
this.value = this.value.slice(0, this.maxLength);
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
<template>
|
||||
<textareaquestion cmsWidgetName="TextAreaContentWidget" maxLength="250" />
|
||||
<textareaquestion v-model="techNotes" cmsWidgetName="TextAreaContentWidget" maxLength="250" />
|
||||
</template>
|
||||
|
||||
<script>
|
||||
|
|
@ -33,6 +33,11 @@ export default {
|
|||
vm.setCmsContent(resultMap.cmsContent);
|
||||
});
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
techNotes: "",
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
textAreaLabelCopy() {
|
||||
return this.getCmsContent("TextAreaContentWidget", "QuestionText");
|
||||
|
|
|
|||
Loading…
Reference in a new issue