{{ colorQuestionText }}
+{{ colorQuestionText }}
- {{buttonLabelSubCopy}} +
+ {{ buttonLabelSubCopy }}
{{ buttonLabel }}
@@ -70,17 +78,29 @@ export default { colLength: String, validationRules: String, selectedValues: [Array, String], + 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]; - } + 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() { @@ -96,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, }); @@ -127,10 +150,12 @@ export default { \ No newline at end of file +