CSR-480: clean up some faulty logic I discovered that was only clearing answers if multi-select
This commit is contained in:
parent
18ae4834d5
commit
c167f1887a
5 changed files with 9 additions and 11 deletions
|
|
@ -112,7 +112,8 @@ describe("buttonQuestion.vue", () => {
|
||||||
const wrapper = shallowMount(buttonQuestion, setupMocks({}));
|
const wrapper = shallowMount(buttonQuestion, setupMocks({}));
|
||||||
await wrapper.setProps({
|
await wrapper.setProps({
|
||||||
answers: ["2022", "2021", "2020"],
|
answers: ["2022", "2021", "2020"],
|
||||||
isMultiSelect: false
|
isMultiSelect: false,
|
||||||
|
modelValue: []
|
||||||
});
|
});
|
||||||
const val = { checkValue: true, value: "2021", }
|
const val = { checkValue: true, value: "2021", }
|
||||||
wrapper.vm.handleCheckedChanged(val);
|
wrapper.vm.handleCheckedChanged(val);
|
||||||
|
|
|
||||||
|
|
@ -133,17 +133,14 @@ export default {
|
||||||
return answer.Name ? answer.Name : answer;
|
return answer.Name ? answer.Name : answer;
|
||||||
},
|
},
|
||||||
handleCheckedChanged(val) {
|
handleCheckedChanged(val) {
|
||||||
|
if(this.selectingInitiatesLoad) {
|
||||||
if(this.isMultiSelect && this.selectedValues) {
|
this.selectedValues = [val.value];
|
||||||
// Add or remove item to array of data to emit
|
} else {
|
||||||
const newSelectedValues = this.selectedValues;
|
|
||||||
|
|
||||||
if(Array.isArray(this.selectedValues)) {
|
if(Array.isArray(this.selectedValues)) {
|
||||||
|
const newSelectedValues = this.selectedValues;
|
||||||
val.checkValue ? newSelectedValues.push(val.value) : newSelectedValues.splice(newSelectedValues.indexOf(val.value), 1);
|
val.checkValue ? newSelectedValues.push(val.value) : newSelectedValues.splice(newSelectedValues.indexOf(val.value), 1);
|
||||||
this.selectedValues = newSelectedValues;
|
this.selectedValues = newSelectedValues;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
this.selectedValues = [val.value];
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -92,7 +92,7 @@ export default {
|
||||||
: this.selectedValues[0];
|
: 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.checkValue = false;
|
||||||
this.handleCheckChange();
|
this.handleCheckChange();
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -92,7 +92,7 @@ export default {
|
||||||
: this.selectedValues[0];
|
: 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.checkValue = false;
|
||||||
this.handleCheckChange();
|
this.handleCheckChange();
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -99,7 +99,7 @@ export default {
|
||||||
: this.selectedValues[0];
|
: 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.checkValue = false;
|
||||||
this.handleCheckChange();
|
this.handleCheckChange();
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue