From 215232663d75118da2db7afd957329f0d8cf6ee1 Mon Sep 17 00:00:00 2001 From: Adam Caouette Date: Mon, 31 Jan 2022 16:26:36 -0500 Subject: [PATCH 01/31] CSR-254: set up damage-location-question --- .../button-question/button-question.vue | 54 ++++++++- .../funnel-footer/funnel-footer.vue | 22 ++++ .../damage-location-question.vue | 109 ++++++++++++++++++ src/layouts/vehicle-damage/vehicle-damage.vue | 69 ++++++++++- src/ux-components/list-card/list-card.vue | 57 ++++++++- 5 files changed, 303 insertions(+), 8 deletions(-) create mode 100644 src/common-components/funnel-footer/funnel-footer.vue create mode 100644 src/layouts/vehicle-damage/damage-location-question/damage-location-question.vue diff --git a/src/common-components/button-question/button-question.vue b/src/common-components/button-question/button-question.vue index 3c818eb8d..6ab38ec16 100644 --- a/src/common-components/button-question/button-question.vue +++ b/src/common-components/button-question/button-question.vue @@ -1,5 +1,6 @@ @@ -41,6 +45,7 @@ import listButton from "@/ux-components/list-button/list-button"; import listButtonHorizontal from "@/ux-components/list-button-horizontal/list-button-horizontal"; import listCard from "@/ux-components/list-card/list-card"; +import { useField } from 'vee-validate'; export default { name: "buttonQuestion", @@ -74,6 +79,9 @@ export default { isOverflowScrollable: Boolean, isWide: Boolean, modelValue: String, + validationRules: Array, + name: String, + value: String, }, computed: { getFieldSetClasses(){ @@ -97,6 +105,7 @@ export default { }, methods: { chooseAnswer(answer) { + console.log('method: chooseAnswer, answer: ', answer); this.$emit("update:modelValue", answer); }, }, @@ -105,6 +114,49 @@ export default { listButtonHorizontal, listCard }, + setup(props) { + console.log('button-question running setup'); + const { + value: inputValue, + errorMessage, + handleBlur, + handleChange, + meta, + } = useField(props.groupName, value => { + if (props.validationRules) { + // console.log('props.validationRules is: ', props.validationRules); + + // console.log("value is: ", value) + // console.log("inputValue is: ", inputValue); + + let validationResults = []; + + props.validationRules.forEach((rule) => { + console.log("BQ 2value is: ", value) + // console.log("2inputValue is: ", inputValue); + if (!rule.test(value)) { + // console.log('uh oh, returning error!', rule.error) + validationResults.push(rule.error); + } + }); + + return (validationResults.length > 0) ? validationResults[0] : true; + } else { + return true; + } + }, { + type: 'checkbox', + checkedValue: props.value, + }); + + return { + // handleChange, + // handleBlur, + errorMessage, + // inputValue, + meta, + }; + }, }; diff --git a/src/common-components/funnel-footer/funnel-footer.vue b/src/common-components/funnel-footer/funnel-footer.vue new file mode 100644 index 000000000..552b31031 --- /dev/null +++ b/src/common-components/funnel-footer/funnel-footer.vue @@ -0,0 +1,22 @@ + + + + diff --git a/src/layouts/vehicle-damage/damage-location-question/damage-location-question.vue b/src/layouts/vehicle-damage/damage-location-question/damage-location-question.vue new file mode 100644 index 000000000..34866e98c --- /dev/null +++ b/src/layouts/vehicle-damage/damage-location-question/damage-location-question.vue @@ -0,0 +1,109 @@ + + + \ No newline at end of file diff --git a/src/layouts/vehicle-damage/vehicle-damage.vue b/src/layouts/vehicle-damage/vehicle-damage.vue index c00669245..ffeb5c3d7 100644 --- a/src/layouts/vehicle-damage/vehicle-damage.vue +++ b/src/layouts/vehicle-damage/vehicle-damage.vue @@ -1,10 +1,35 @@ @@ -13,6 +38,15 @@ import funnelHeader from "@/common-components/funnel-header/funnel-header"; import vehicleBanner from "@/common-components/vehicle-banner/vehicle-banner"; import funnelSubHeader from "@/common-components/funnel-sub-header/funnel-sub-header"; +import replaceOptionsQuestion from "@/layouts/vehicle-damage/replace-options-question/replace-options-question"; +import damageLocationQuestion from "@/layouts/vehicle-damage/damage-location-question/damage-location-question"; +import textInput from "@/common-components/text-input/text-input"; + +import funnelFooter from "@/common-components/funnel-footer/funnel-footer"; + +import { Form, ErrorMessage } from 'vee-validate'; + + // Supporting files import { fetchCmsContentForPage } from "@/helpers/cms-content-helper"; import { settleAllPromises } from "@/helpers/layout-helper"; @@ -37,7 +71,7 @@ export default ({ resultKey: "damageOptions", promise: damageOptionsPromise }, - ]; + ]; const resultMap = await settleAllPromises(promiseResultMap); @@ -52,14 +86,45 @@ export default ({ vm.$refs.funnelSubHeader.initializeComponent( resultMap.cmsContent.FunnelSubHeaderWidget ); - // use resultMap.damageOptions for damage options + vm.$refs.damageLocationQuestion.initializeComponent( + resultMap.cmsContent.DamageLocationQuestion + ); + // vm.$refs.replaceOptionsQuestion.initializeComponent( + // resultMap.cmsContent.DriverSideReplaceOptionsQuestion, resultMap.damageOptions.driverSideOptions.availableReplacementOptions + // ); + console.log(resultMap) }); }, components: { + Form, funnelHeader, vehicleBanner, funnelSubHeader, + damageLocationQuestion, + // replaceOptionsQuestion, + funnelFooter, + // textInput, + }, + methods: { + onSubmit(values) { + window.alert('Success! Submitted values: ' + JSON.stringify(values, null ,2)) + console.log('submitted: ', JSON.stringify(values, null ,2)); + }, + onInvalidSubmit({ values, errors, results }) { + // identify the first error field and put focus on it + console.log("values: ", values); + console.log("errors: ", errors); + console.log("results: ", results); + // get errorEls and order by alpha + const errorEls = Object.keys(errors).sort(); + const firstErrorEl = errorEls[0]; + console.log('firstErrorEl: ', firstErrorEl); + if (firstErrorEl) { + const qsString = "[data-focus-target='" + firstErrorEl + "']"; + document.querySelector(qsString).focus(); + } + } }, }); diff --git a/src/ux-components/list-card/list-card.vue b/src/ux-components/list-card/list-card.vue index 17c8193f0..2389d8ccc 100644 --- a/src/ux-components/list-card/list-card.vue +++ b/src/ux-components/list-card/list-card.vue @@ -1,8 +1,18 @@ @@ -47,7 +48,7 @@ import listButton from "@/ux-components/list-button/list-button"; import listButtonHorizontal from "@/ux-components/list-button-horizontal/list-button-horizontal"; import listCard from "@/ux-components/list-card/list-card"; -import { useField } from 'vee-validate'; +import { useField, ErrorMessage } from 'vee-validate'; export default { name: "buttonQuestion", @@ -132,6 +133,9 @@ export default { this.$emit("update:modelValue", answer); }, handleCheckedChanged(val) { + + console.log('meta is now ', this.meta) + // Add or remove item to array of data to emit val.isChecked ? this.modelValueAnswers.push(val.buttonId) : this.modelValueAnswers.splice(this.modelValueAnswers.indexOf(val.buttonId), 1); const answersToEmit = this.modelValueAnswers.length ? this.modelValueAnswers : undefined; @@ -142,50 +146,29 @@ export default { listButton, listButtonHorizontal, listCard, + ErrorMessage, }, - setup(props) { - console.log('button-question running setup'); - const { - value: inputValue, - errorMessage, - handleBlur, - handleChange, - meta, - } = useField(props.groupName, value => { - if (props.validationRules) { - // console.log('props.validationRules is: ', props.validationRules); - - // console.log("value is: ", value) - // console.log("inputValue is: ", inputValue); - - let validationResults = []; - - props.validationRules.forEach((rule) => { - console.log("BQ 2value is: ", value) - // console.log("2inputValue is: ", inputValue); - if (!rule.test(value)) { - // console.log('uh oh, returning error!', rule.error) - validationResults.push(rule.error); - } - }); - - return (validationResults.length > 0) ? validationResults[0] : true; - } else { - return true; - } - }, { - type: 'checkbox', - checkedValue: props.value, - }); + // setup(props) { + // console.log('button-question running setup'); + // const { + // value: inputValue, + // errorMessage, + // handleBlur, + // handleChange, + // meta, + // } = useField(props.groupName, undefined, { + // type: 'checkbox', + // checkedValue: props.value, + // }); - return { - // handleChange, - // handleBlur, - errorMessage, - // inputValue, - meta, - }; - }, + // return { + // // handleChange, + // // handleBlur, + // errorMessage, + // // inputValue, + // meta, + // }; + // }, }; diff --git a/src/layouts/vehicle-damage/damage-location-question/damage-location-question.vue b/src/layouts/vehicle-damage/damage-location-question/damage-location-question.vue index bd583a378..7196e8f43 100644 --- a/src/layouts/vehicle-damage/damage-location-question/damage-location-question.vue +++ b/src/layouts/vehicle-damage/damage-location-question/damage-location-question.vue @@ -1,5 +1,5 @@ @@ -55,10 +56,10 @@ export default ({ test: (value) => { // console.log('required value is... ', value); if (!value || value.length < 1) { - // console.log('return false') + console.log('DLQ should return false') return false; } - // console.log('no if, return true') + console.log('DLQ should return true') return true; }, error: 'Please select damage location' diff --git a/src/layouts/vehicle-damage/replace-options-question/replace-options-question.vue b/src/layouts/vehicle-damage/replace-options-question/replace-options-question.vue index 2c46d96fd..da96d2d08 100644 --- a/src/layouts/vehicle-damage/replace-options-question/replace-options-question.vue +++ b/src/layouts/vehicle-damage/replace-options-question/replace-options-question.vue @@ -1,6 +1,8 @@