From 592e21289ed14cbfced1fe4c4307db20b5bba9e5 Mon Sep 17 00:00:00 2001 From: Michaela Brydon Date: Mon, 15 Jan 2024 16:09:51 -0500 Subject: [PATCH] Prepopulating vehicle selection page with content from store --- .../vehicle-question/vehicle-question.vue | 9 +++++---- .../vehicle-selection/vehicle-selection.vue | 18 ++++++++++++++---- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/layouts/vehicle-selection/vehicle-question/vehicle-question.vue b/src/layouts/vehicle-selection/vehicle-question/vehicle-question.vue index 1a8e335a..aea4dd8d 100644 --- a/src/layouts/vehicle-selection/vehicle-question/vehicle-question.vue +++ b/src/layouts/vehicle-selection/vehicle-question/vehicle-question.vue @@ -32,9 +32,9 @@ export default { get() { return this.selectedIndex?.toString(); }, - set(newValue) { - this.selectedIndex = newValue; - newValue = newValue != null && newValue > -1 ? this.values[newValue] : null; + set(newIndex) { + this.selectedIndex = newIndex; + const newValue = newIndex != null && newIndex > -1 ? this.values[newIndex] : null; this.$emit('update:modelValue', newValue); } } @@ -46,7 +46,8 @@ export default { if (this.values.length === 1) { this.selectedValue = 0; } else { - this.selectedValue = null; + const valueIndex = this.values.indexOf(this.modelValue); + this.selectedValue = valueIndex === -1 ? null : valueIndex; } }, clearValues() { diff --git a/src/layouts/vehicle-selection/vehicle-selection.vue b/src/layouts/vehicle-selection/vehicle-selection.vue index 6e707b49..4d0d16ed 100644 --- a/src/layouts/vehicle-selection/vehicle-selection.vue +++ b/src/layouts/vehicle-selection/vehicle-selection.vue @@ -134,11 +134,12 @@ export default { validationRules: String }, data() { + const { year, make, model, style } = useMainStore().order.vehicle; return { - selectedYear: null, - selectedMake: null, - selectedModel: null, - selectedStyle: null + selectedYear: year, + selectedMake: make, + selectedModel: model, + selectedStyle: style }; }, computed: { @@ -176,6 +177,15 @@ export default { }, mounted() { this.$refs.vehicleYearQuestion.getNewValues(); + if (this.selectedYear) { + this.$refs.vehicleMakeQuestion.getNewValues(); + } + if (this.selectedMake) { + this.$refs.vehicleModelQuestion.getNewValues(); + } + if (this.selectedModel) { + this.$refs.vehicleStyleQuestion.getNewValues(); + } }, methods: { arePagePrerequisitesValid() {