diff --git a/src/layouts/vehicle-parts/glass-part-question/glass-part-question.vue b/src/layouts/vehicle-parts/glass-part-question/glass-part-question.vue index e923af0c6..9be24b91b 100644 --- a/src/layouts/vehicle-parts/glass-part-question/glass-part-question.vue +++ b/src/layouts/vehicle-parts/glass-part-question/glass-part-question.vue @@ -82,16 +82,10 @@ export default { glassName: String, glassLocation: String, colorAnswers: Array, - modelValue: { - type: Object, - default: () => ({}), - }, + modelValue: Object, }, mounted() { this.LoadPreselectedValues(); - if (Object.keys(this.featureListData).length === 1) { - this.AutoSelectTintIfOnlyOneColor(Object.keys(this.featureListData)[0]); - } }, components: { listCard, @@ -144,6 +138,7 @@ export default { }, }, methods: { + // Initialize the component data initializeComponent(cmsContent) { this.glassColorQuestion = cmsContent.ColorQuestionWidget.QuestionText; this.glassFeatureQuestion = cmsContent.FeatureQuestionWidget.QuestionText; @@ -191,35 +186,30 @@ export default { }); }, - AutoSelectTintIfOnlyOneColor(tintColor) { - this.selectedTint[tintColor] = { - buttonId: `${this.glassLocation}-${this.glassName}-${tintColor}`, - checkValue: "", - value: `${this.glassLocation}-${this.glassName}-${tintColor}`, - }; - }, - + // Loads the preselected values from the store. LoadPreselectedValues() { - if (Object.keys(this.modelValue).length !== 0) { - // Populate button-question model-value if parts data already exists in VueX - const alreadyPopulatedPartsData = - this.$store.getters.lineItems.glassParts; + this.$nextTick(() => { + if (this.modelValue !== undefined) { + // Populate button-question model-value if parts data already exists in VueX + const alreadyPopulatedPartsData = + this.$store.getters.lineItems.glassParts; - Object.keys(alreadyPopulatedPartsData).forEach((key) => { - const partNumber = alreadyPopulatedPartsData[key].partNumber; - const tintColor = alreadyPopulatedPartsData[key].color; + Object.keys(alreadyPopulatedPartsData).forEach((key) => { + const partNumber = alreadyPopulatedPartsData[key].partNumber; + const tintColor = alreadyPopulatedPartsData[key].color; - Object.keys(this.modelValue).forEach((key) => { - if (this.modelValue[key][0] === partNumber) { - this.selectedTint[tintColor] = { - buttonId: `${this.glassLocation}-${this.glassName}-${tintColor}`, - checkValue: "", - value: `${this.glassLocation}-${this.glassName}-${tintColor}`, - }; - } + Object.keys(this.modelValue).forEach((key) => { + if (this.modelValue[key][0] === partNumber) { + this.selectedTint[tintColor] = { + buttonId: `${this.glassLocation}-${this.glassName}-${tintColor}`, + checkValue: "", + value: `${this.glassLocation}-${this.glassName}-${tintColor}`, + }; + } + }); }); - }); - } + } + }); }, }, }; diff --git a/src/layouts/vehicle-parts/vehicle-parts.vue b/src/layouts/vehicle-parts/vehicle-parts.vue index 39c8bbbf3..41e17f601 100644 --- a/src/layouts/vehicle-parts/vehicle-parts.vue +++ b/src/layouts/vehicle-parts/vehicle-parts.vue @@ -1,42 +1,26 @@ diff --git a/src/ux-components/list-card/list-card.vue b/src/ux-components/list-card/list-card.vue index 832f33c6b..8c5ac9e23 100644 --- a/src/ux-components/list-card/list-card.vue +++ b/src/ux-components/list-card/list-card.vue @@ -2,7 +2,11 @@
- {{buttonLabel}} + {{ buttonLabel }}

-

- {{buttonLabelSubCopy}} +

+ {{ buttonLabelSubCopy }}

{{ buttonLabel }}

@@ -73,23 +81,26 @@ export default { modelValue: Object, hasError: Boolean, }, - data(){ + data() { return { checkValue: Boolean, + }; + }, + created() { + if (Array.isArray(this.selectedValues)) { + this.checkValue = this.isMultiSelect + ? this.selectedValues.includes(this.value) + : this.selectedValues[0]; } }, - created(){ - if(Array.isArray(this.selectedValues)){ - this.checkValue = this.isMultiSelect ? this.selectedValues.includes(this.value) : this.selectedValues[0]; - } - this.$nextTick(() => { - if(Object.keys(this.modelValue).length > 0) { - this.checkValue = this.modelValue.value; - const emitEvent = { checkValue: this.checkValue, value: this.value.toString(), buttonId: this.buttonID.toString() }; - this.$emit('isCheckedChanged', emitEvent); - this.$emit('update:modelValue', emitEvent); + watch: { + // Changing this will impact pre-selection data loads on vehicle-parts. + // If changed, please regression test that vehicle-parts data still loads correctly with previous selections. + modelValue(newVal) { + if (newVal !== undefined) { + this.checkValue = newVal.value; } - }) + }, }, computed: { getLabelClasses() { @@ -105,23 +116,26 @@ export default { }, }, methods: { - handleCheckChange(newValue, oldValue){ - const isInitialization = typeof(oldValue) === 'function'; + handleCheckChange(newValue, oldValue) { + const isInitialization = typeof oldValue === "function"; if (!isInitialization) { - const emitEvent = { checkValue: this.checkValue, value: this.value.toString(), buttonId: this.buttonID.toString() }; - this.$emit('isCheckedChanged', emitEvent); - this.$emit('update:modelValue', emitEvent); + const emitEvent = { + checkValue: this.checkValue, + value: this.value.toString(), + buttonId: this.buttonID.toString(), + }; + this.$emit("isCheckedChanged", emitEvent); + this.$emit("update:modelValue", emitEvent); } - } + }, }, setup(props) { const inputType = props.isMultiSelect ? "checkbox" : "radio"; const { - value: inputValue, - handleChange, - errors, - } = useField(props.groupName, props.validationRules, - { + value: inputValue, + handleChange, + errors, + } = useField(props.groupName, props.validationRules, { type: inputType, checkedValue: props.value, }); @@ -136,10 +150,12 @@ export default { \ No newline at end of file +