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>
|
<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"
|
||||||
:maxlength="maxLength"
|
:maxlength="maxLength"
|
||||||
role="textbox"
|
role="textbox"
|
||||||
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
|
||||||
{{ remainingCount }}/{{ maxLength }} characters remaining
|
tabindex="0"
|
||||||
</p>
|
class="caption mt-2 mb-0"
|
||||||
</div>
|
id="charactersremaining"
|
||||||
|
:style="{ color: countdownColor }">
|
||||||
|
{{ remainingCount }}/{{ maxLength }} characters remaining
|
||||||
|
</p>
|
||||||
|
</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;
|
||||||
|
|
||||||
|
|
@ -47,11 +46,11 @@ export default {
|
||||||
|
|
||||||
switch (typeof modelValue) {
|
switch (typeof modelValue) {
|
||||||
case "number":
|
case "number":
|
||||||
initialValue = modelValue;
|
initialValue = modelValue;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
initialValue = modelValue && modelValue.length > 0 ? modelValue : "";
|
initialValue = modelValue && modelValue.length > 0 ? modelValue : "";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
const fieldOptions = {
|
const fieldOptions = {
|
||||||
|
|
@ -73,18 +72,19 @@ 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>
|
||||||
|
|
|
||||||
|
|
@ -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");
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue