diff --git a/src/common-components/button-question/button-question.spec.js b/src/common-components/button-question/button-question.spec.js index 464fcf245..d36b73012 100644 --- a/src/common-components/button-question/button-question.spec.js +++ b/src/common-components/button-question/button-question.spec.js @@ -53,7 +53,7 @@ describe("buttonQuestion.vue", () => { answers: ["2022", "2021", "2020"], isMultiSelect: false }); - const val = {isChecked: true, buttonId: "2021", } + const val = {checkValue: true, value: "2021", } wrapper.vm.handleCheckedChanged(val); // Assert expect(wrapper.emitted()["update:modelValue"][0]).toEqual([["2021"]]); @@ -69,7 +69,7 @@ describe("buttonQuestion.vue", () => { isMultiSelect: true, } }); - const val = {isChecked: true, buttonId: "2019", } + const val = {checkValue: true, value: "2019", } wrapper.vm.handleCheckedChanged(val); // Assert expect(wrapper.emitted()["update:modelValue"][0]).toEqual([["2022", "2021", "2020", "2019"]]); diff --git a/src/common-components/button-question/button-question.vue b/src/common-components/button-question/button-question.vue index e8cf4a967..71d79b31f 100644 --- a/src/common-components/button-question/button-question.vue +++ b/src/common-components/button-question/button-question.vue @@ -12,7 +12,7 @@ v-for="answer in answers" :key="answer.Name ? answer.Name : answer" @isCheckedChanged="handleCheckedChanged" - :buttonID="answer.Name ? answer.Name : answer" + :buttonID="answer.Name ? groupName + '-' + answer.Name : groupName + '-' + answer" :value="answer.Name ? answer.Name : answer" :buttonLabel="answer.Text ? answer.Text : answer" :buttonLabelSubCopy="answer.SubText" @@ -29,7 +29,7 @@ :altText="answer.Name ? answer.Name : answer" screenReaderOnlyText="(opens new window)" :colLength="getColLength" - :selectedButtonIDs="selectedValues" + :selectedValues="selectedValues" data-test="button" :validationRules="validationRules" /> @@ -124,11 +124,13 @@ export default { handleCheckedChanged(val) { if(this.isMultiSelect) { // Add or remove item to array of data to emit - const newSelectedValues = this.selectedValues; - val.isChecked ? newSelectedValues.push(val.buttonId) : newSelectedValues.splice(newSelectedValues.indexOf(val.buttonId), 1); - this.selectedValues = newSelectedValues; + if(Array.isArray(this.selectedValues)) { + const newSelectedValues = this.selectedValues; + val.checkValue ? newSelectedValues.push(val.value) : newSelectedValues.splice(newSelectedValues.indexOf(val.value), 1); + this.selectedValues = newSelectedValues; + } } else { - this.selectedValues = [val.buttonId]; + this.selectedValues = [val.value]; } }, }, diff --git a/src/ux-components/list-button-horizontal/list-button-horizontal.spec.js b/src/ux-components/list-button-horizontal/list-button-horizontal.spec.js index d1175620c..f95b378d7 100644 --- a/src/ux-components/list-button-horizontal/list-button-horizontal.spec.js +++ b/src/ux-components/list-button-horizontal/list-button-horizontal.spec.js @@ -161,7 +161,7 @@ describe("list-button-horizontal.vue", () => { propsData: { isRadioHorizontal: true, buttonLabel: "Windshield", - buttonID: "List Card Checkbox", + value: "List Card Checkbox", groupID: "radio-demo-1", groupName: "radio 1", buttonImage: "windshield-damage.svg", @@ -172,7 +172,7 @@ describe("list-button-horizontal.vue", () => { }); wrapper.vm.handleCheckChange(); // Assert - expect(wrapper.emitted()["isCheckedChanged"][0]).toEqual([{buttonId: "List Card Checkbox", isChecked: Boolean}]); + expect(wrapper.emitted()["isCheckedChanged"][0]).toEqual([{value: "List Card Checkbox", checkValue: Boolean}]); }); it("Should set checkValue data if selectedButtonIDs has value(s)", async () => { @@ -189,7 +189,7 @@ describe("list-button-horizontal.vue", () => { isWide: false, modelValue: ["List Card Checkbox"], isMultiSelect: false, - selectedButtonIDs: ["Car-Front"] + selectedValues: ["Car-Front"] }, }); // Assert diff --git a/src/ux-components/list-button-horizontal/list-button-horizontal.vue b/src/ux-components/list-button-horizontal/list-button-horizontal.vue index 35a01ded9..b6f33676b 100644 --- a/src/ux-components/list-button-horizontal/list-button-horizontal.vue +++ b/src/ux-components/list-button-horizontal/list-button-horizontal.vue @@ -9,7 +9,7 @@ :type="isMultiSelect ? 'checkbox' : 'radio'" :id="buttonID" :name="groupName" - :value="buttonID" + :value="value" :aria-required="isRequired" :data-focus-target="groupName" v-model="checkValue" @@ -69,7 +69,7 @@ export default { type: String, default: "", }, - selectedButtonIDs: [Array, String], + selectedValues: [Array, String], hasError: Boolean, }, data() { @@ -79,8 +79,8 @@ export default { }; }, created(){ - if(this.selectedButtonIDs){ - this.checkValue = this.isMultiSelect ? this.selectedButtonIDs.includes(this.buttonID) : this.selectedButtonIDs[0]; + if(Array.isArray(this.selectedValues)){ + this.checkValue = this.isMultiSelect ? this.selectedValues.includes(this.value) : this.selectedValues[0]; } }, methods: { @@ -97,7 +97,7 @@ export default { handleCheckChange(newValue, oldValue){ const isInitialization = typeof(oldValue) === 'function'; if (!isInitialization) { - this.$emit('isCheckedChanged', { isChecked: this.checkValue, buttonId: this.buttonID.toString() }); + this.$emit('isCheckedChanged', { checkValue: this.checkValue, value: this.value.toString() }); } } }, diff --git a/src/ux-components/list-button/list-button.spec.js b/src/ux-components/list-button/list-button.spec.js index 1e900ce62..18707e45f 100644 --- a/src/ux-components/list-button/list-button.spec.js +++ b/src/ux-components/list-button/list-button.spec.js @@ -159,7 +159,7 @@ describe("list-button.vue", () => { propsData: { isRadioHorizontal: true, buttonLabel: "Windshield", - buttonID: "List Card Checkbox", + value: "List Card Checkbox", groupID: "radio-demo-1", groupName: "radio 1", buttonImage: "windshield-damage.svg", @@ -170,7 +170,7 @@ describe("list-button.vue", () => { }); wrapper.vm.handleCheckChange(); // Assert - expect(wrapper.emitted()["isCheckedChanged"][0]).toEqual([{buttonId: "List Card Checkbox", isChecked: Boolean}]); + expect(wrapper.emitted()["isCheckedChanged"][0]).toEqual([{value: "List Card Checkbox", checkValue: Boolean}]); }); it("Should set checkValue data if selectedButtonIDs has value(s)", async () => { @@ -186,7 +186,7 @@ describe("list-button.vue", () => { isRequired: true, isWide: false, modelValue: ["List Card Checkbox"], - selectedButtonIDs: ["Car-Front"] + selectedValues: ["Car-Front"] }, }); // Assert diff --git a/src/ux-components/list-button/list-button.vue b/src/ux-components/list-button/list-button.vue index 04a9c18e7..4727f9743 100644 --- a/src/ux-components/list-button/list-button.vue +++ b/src/ux-components/list-button/list-button.vue @@ -9,7 +9,7 @@ :type="isMultiSelect ? 'checkbox' : 'radio'" :id="buttonID" :name="groupName" - :value="buttonID" + :value="value" :aria-required="isRequired" :data-focus-target="groupName" v-model="checkValue" @@ -71,7 +71,7 @@ export default { type: [String, Number], default: "", }, - selectedButtonIDs: [Array, String], + selectedValues: [Array, String], hasError: Boolean, }, data() { @@ -81,8 +81,8 @@ export default { }; }, created(){ - if(this.selectedButtonIDs){ - this.checkValue = this.isMultiSelect ? this.selectedButtonIDs.includes(this.buttonID) : this.selectedButtonIDs[0]; + if(Array.isArray(this.selectedValues)){ + this.checkValue = this.isMultiSelect ? this.selectedValues.includes(this.value) : this.selectedValues[0]; } }, methods: { @@ -99,7 +99,7 @@ export default { handleCheckChange(newValue, oldValue){ const isInitialization = typeof(oldValue) === 'function'; if (!isInitialization) { - this.$emit('isCheckedChanged', { isChecked: this.checkValue, buttonId: this.buttonID.toString() }); + this.$emit('isCheckedChanged', { checkValue: this.checkValue, value: this.value.toString() }); } }, }, diff --git a/src/ux-components/list-card/list-card.spec.js b/src/ux-components/list-card/list-card.spec.js index 30af40ec3..a345c7b18 100644 --- a/src/ux-components/list-card/list-card.spec.js +++ b/src/ux-components/list-card/list-card.spec.js @@ -197,7 +197,7 @@ describe("list-card.vue", () => { propsData: { isRadioHorizontal: true, buttonLabel: "Windshield", - buttonID: "List Card Checkbox", + value: "List Card Checkbox", groupID: "radio-demo-1", groupName: "radio 1", buttonImage: "windshield-damage.svg", @@ -208,7 +208,7 @@ describe("list-card.vue", () => { }); wrapper.vm.handleCheckChange(); // Assert - expect(wrapper.emitted()["isCheckedChanged"][0]).toEqual([{buttonId: "List Card Checkbox", isChecked: Boolean}]); + expect(wrapper.emitted()["isCheckedChanged"][0]).toEqual([{value: "List Card Checkbox", checkValue: Boolean}]); }); it("Should set checkValue data if selectedButtonIDs has value(s)", async () => { @@ -217,14 +217,14 @@ describe("list-card.vue", () => { propsData: { isRadioHorizontal: true, buttonLabel: "Windshield", - buttonID: "List Card Checkbox", + value: "List Card Checkbox", groupID: "radio-demo-1", groupName: "radio 1", buttonImage: "windshield-damage.svg", isRequired: true, isWide: false, modelValue: ["List Card Checkbox"], - selectedButtonIDs: ["Car-Front"] + selectedValues: ["Car-Front"] }, }); // Assert diff --git a/src/ux-components/list-card/list-card.vue b/src/ux-components/list-card/list-card.vue index 1fe25c408..59518deb7 100644 --- a/src/ux-components/list-card/list-card.vue +++ b/src/ux-components/list-card/list-card.vue @@ -8,7 +8,7 @@ :type="isMultiSelect ? 'checkbox' : 'radio'" :id="buttonID" :name="groupName" - :value="buttonID" + :value="value" :aria-required="isRequired" :data-focus-target="groupName" @click="handleChange(value)" @@ -70,7 +70,7 @@ export default { }, colLength: String, validationRules: String, - selectedButtonIDs: [Array, String], + selectedValues: [Array, String], hasError: Boolean, }, data(){ @@ -79,8 +79,8 @@ export default { } }, created(){ - if(this.selectedButtonIDs){ - this.checkValue = this.isMultiSelect ? this.selectedButtonIDs.includes(this.buttonID) : this.selectedButtonIDs[0]; + if(Array.isArray(this.selectedValues)){ + this.checkValue = this.isMultiSelect ? this.selectedValues.includes(this.value) : this.selectedValues[0]; } }, computed: { @@ -100,7 +100,7 @@ export default { handleCheckChange(newValue, oldValue){ const isInitialization = typeof(oldValue) === 'function'; if (!isInitialization) { - this.$emit('isCheckedChanged', { isChecked: this.checkValue, buttonId: this.buttonID.toString() }); + this.$emit('isCheckedChanged', { checkValue: this.checkValue, value: this.value.toString() }); } } }, diff --git a/src/ux-components/radio/radio.vue b/src/ux-components/radio/radio.vue index aedead0eb..209b7ddab 100644 --- a/src/ux-components/radio/radio.vue +++ b/src/ux-components/radio/radio.vue @@ -54,7 +54,7 @@ export default { handleCheckChange(newValue, oldValue){ const isInitialization = typeof(oldValue) === 'function'; if (!isInitialization) { - this.$emit('isCheckedChanged', { isChecked: this.checkValue, buttonId: this.buttonID.toString() }); + this.$emit('isCheckedChanged', { checkValue: this.checkValue, value: this.value.toString() }); } } },