CSR-480: clean up some faulty logic I discovered that was only clearing answers if multi-select

This commit is contained in:
Adam Caouette 2022-06-09 16:51:59 -04:00
parent 18ae4834d5
commit c167f1887a
5 changed files with 9 additions and 11 deletions

View file

@ -112,7 +112,8 @@ describe("buttonQuestion.vue", () => {
const wrapper = shallowMount(buttonQuestion, setupMocks({}));
await wrapper.setProps({
answers: ["2022", "2021", "2020"],
isMultiSelect: false
isMultiSelect: false,
modelValue: []
});
const val = { checkValue: true, value: "2021", }
wrapper.vm.handleCheckedChanged(val);

View file

@ -133,17 +133,14 @@ export default {
return answer.Name ? answer.Name : answer;
},
handleCheckedChanged(val) {
if(this.isMultiSelect && this.selectedValues) {
// Add or remove item to array of data to emit
const newSelectedValues = this.selectedValues;
if(this.selectingInitiatesLoad) {
this.selectedValues = [val.value];
} else {
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.value];
}
},
},

View file

@ -92,7 +92,7 @@ export default {
: this.selectedValues[0];
}
},
unmounted() { // needed to clear this button's selectedValues if it is removed
unmounted() { // needed to clear this button's selectedValues if it is removed to keep validation in sync
this.checkValue = false;
this.handleCheckChange();
},

View file

@ -92,7 +92,7 @@ export default {
: this.selectedValues[0];
}
},
unmounted() { // needed to clear this button's selectedValues if it is removed
unmounted() { // needed to clear this button's selectedValues if it is removed to keep validation in sync
this.checkValue = false;
this.handleCheckChange();
},

View file

@ -99,7 +99,7 @@ export default {
: this.selectedValues[0];
}
},
unmounted() { // needed to clear this button's selectedValues if it is removed
unmounted() { // needed to clear this button's selectedValues if it is removed to keep validation in sync
this.checkValue = false;
this.handleCheckChange();
},