Add v-model functionality, rename and move component.

This commit is contained in:
Bryan Mauger 2023-05-31 16:01:05 -04:00
parent 8e98b62b2e
commit 3fd18cb442
4 changed files with 42 additions and 12 deletions

View file

@ -2,6 +2,7 @@
<!-- Checkbox groups MUST be wrapped in a <fieldset> and <legend> tag --> <!-- Checkbox groups MUST be wrapped in a <fieldset> and <legend> tag -->
<div class="form-check ui-checkbox" :class="[hasError ? 'has-error' : '']"> <div class="form-check ui-checkbox" :class="[hasError ? 'has-error' : '']">
<input <input
v-model="value"
class="form-check-input" class="form-check-input"
type="checkbox" type="checkbox"
aria-checked="false" aria-checked="false"
@ -10,7 +11,7 @@
:tabindex="tabIndex" :tabindex="tabIndex"
:aria-required="isRequired" /> :aria-required="isRequired" />
<label class="d-flex align-items-start" :for="buttonID"> <label class="d-flex align-items-start" :for="buttonID">
<p v-if="checkboxLabel" class="m-0">{{ checkboxLabel }}</p> <p v-html="checkboxLabelCopy" class="m-0"></p>
<span v-if="screenReaderOnlyText" class="sr-only">{{ screenReaderOnlyText }}</span> <span v-if="screenReaderOnlyText" class="sr-only">{{ screenReaderOnlyText }}</span>
</label> </label>
</div> </div>
@ -18,15 +19,48 @@
<script> <script>
export default { export default {
name: "checkbox", name: "checkboxQuestion",
setup(props) {
const inputId = !props.customInputId ? `input-${crypto.randomUUID()}` : props.customInputId;
const propsClone = Object.assign({}, props);
const modelValue = propsClone.modelValue;
let initialValue;
switch (typeof modelValue) {
case "checked":
initialValue = modelValue;
break;
default:
initialValue = modelValue && modelValue.checked === false ? modelValue : "";
break;
}
const fieldOptions = {
type: "checkbox",
value: modelValue,
initialValue: initialValue,
};
},
data() {
return {
value: [],
};
},
computed: {
checkboxLabelCopy() {
return this.getCmsContent("TextMeQuestionWidget", "QuestionText");
},
},
props: { props: {
cmsWidgetName: String,
checkboxName: String, checkboxName: String,
buttonID: String, buttonID: String,
tabIndex: Number, tabIndex: Number,
checkboxLabel: String,
screenReaderOnlyText: String, screenReaderOnlyText: String,
isRequired: Boolean, isRequired: Boolean,
hasError: Boolean, hasError: Boolean,
modelValue: Boolean,
}, },
}; };
</script> </script>

View file

@ -76,7 +76,7 @@ export default {
}, },
urgentCountdown() { urgentCountdown() {
return this.remainingCount <= this.maxLength * 0.1 ? true : false; return this.remainingCount <= this.maxLength * 0.1 ? true : false;
} },
}, },
methods: { methods: {
updateCount() { updateCount() {

View file

@ -29,11 +29,10 @@
v-model="phoneNumber" v-model="phoneNumber"
isRequired isRequired
validationRules="phone-number-required" /> validationRules="phone-number-required" />
<checkbox <checkboxQuestion
class="mb-5" class="mb-5"
cmsWidgetName="TextMeQuestionWidget" cmsWidgetName="TextMeQuestionWidget"
:checkboxLabel="checkboxLabelCopy" v-model="textMeUpdates" />
v-model="textMeUpdates"/>
<textareaQuestion <textareaQuestion
class="mb-4" class="mb-4"
v-model="techNotes" v-model="techNotes"
@ -58,7 +57,7 @@ import textareaQuestion from "@/digital-components/textarea-question/textarea-qu
import textboxQuestion from "@/digital-components/textbox-question/textbox-question"; import textboxQuestion from "@/digital-components/textbox-question/textbox-question";
import phoneNumberQuestion from "@/digital-components/phonenumber-question/phonenumber-question"; import phoneNumberQuestion from "@/digital-components/phonenumber-question/phonenumber-question";
import textBlock from "@/digital-components/text-block/text-block"; import textBlock from "@/digital-components/text-block/text-block";
import checkbox from "@/ux-components/checkbox/checkbox"; import checkboxQuestion from "@/digital-components/checkbox-question/checkbox-question";
//Supporting files //Supporting files
import { fetchCmsContentForPage } from "@/helpers/cms-content-helper"; import { fetchCmsContentForPage } from "@/helpers/cms-content-helper";
import { settleAllPromises } from "@/helpers/layout-helper"; import { settleAllPromises } from "@/helpers/layout-helper";
@ -117,9 +116,6 @@ export default {
textAreaLabelCopy() { textAreaLabelCopy() {
return this.getCmsContent("TextAreaContentWidget", "QuestionText"); return this.getCmsContent("TextAreaContentWidget", "QuestionText");
}, },
checkboxLabelCopy() {
return this.getCmsContent("TextMeQuestionWidget", "QuestionText");
},
}, },
components: { components: {
funnelHeader, funnelHeader,
@ -130,7 +126,7 @@ export default {
Form, Form,
textBlock, textBlock,
phoneNumberQuestion, phoneNumberQuestion,
checkbox checkboxQuestion,
}, },
}; };
</script> </script>