CSR-762 Fix multiselect

This commit is contained in:
Katie 2022-09-19 10:23:30 -04:00
parent 24ddb9f8a5
commit c5fb168161
4 changed files with 28 additions and 10 deletions

View file

@ -81,17 +81,30 @@ export default {
}, },
methods: { methods: {
handleSelectionChange(event) { handleSelectionChange(event) {
// console.log(event); console.log(event);
// console.log(this.value); // console.log(this.value);
// console.log(this.modelValue); // console.log(this.modelValue);
let isChecked = event.target.checked; // let isChecked = event.target.checked;
// console.log("BM value: ", this.value); // console.log("BM value: ", this.value);
// let valueToEmit; // let valueToEmit;
if (this.isMultiSelect && this.modelValue instanceof Array) { console.log("isMultiselect")
let newValue = [...this.modelValue]; console.log(this.isMultiSelect)
if (isChecked && !this.modelValue.includes(this.value)) { console.log({
modelValue: this.modelValue,
isMultiselect: this.isMultiSelect
})
if (this.isMultiSelect && (this.modelValue instanceof Array || this.modelValue == null)) {
let newValue = this.modelValue ? [...this.modelValue] : [];
console.log("newValue", newValue)
console.log({
newValue: newValue,
// isChecked: isChecked
})
if (!newValue.includes(this.value)) {
console.log("isChecked")
newValue.push(this.value); newValue.push(this.value);
} else { } else {
console.log("isn't checked")
newValue.splice(newValue.indexOf(this.value), 1); newValue.splice(newValue.indexOf(this.value), 1);
} }
@ -111,6 +124,7 @@ export default {
console.log("emitting"); console.log("emitting");
console.log(e); console.log(e);
this.handleSelectionChange(e); this.handleSelectionChange(e);
console.log("valueToEmit")
console.log(this.valueToEmit) console.log(this.valueToEmit)
this.$emit("change", this.valueToEmit); this.$emit("change", this.valueToEmit);
}, },

View file

@ -7,7 +7,7 @@
:groupName="groupName" :groupName="groupName"
buttonType="listCard" buttonType="listCard"
isRequired isRequired
v-model="selectedDamageLocations" v-model="selectedValue"
validationRules="damage-location-required" validationRules="damage-location-required"
/> />
</div> </div>
@ -19,16 +19,18 @@ import store from "@/store";
import { defineRule } from "vee-validate"; import { defineRule } from "vee-validate";
import { required } from "@/helpers/validation-rules"; import { required } from "@/helpers/validation-rules";
import { errorMessages } from "@/constants/error-messages"; import { errorMessages } from "@/constants/error-messages";
import buttonQuestionWrapperMixin from "@/mixins/button-question-wrapper-mixin"
// DEFINE VALIDATION RULES // DEFINE VALIDATION RULES
defineRule("damage-location-required", required(errorMessages.DAMAGE_LOCATION_REQUIRED)); defineRule("damage-location-required", required(errorMessages.DAMAGE_LOCATION_REQUIRED));
export default ({ export default ({
name: "damageLocationQuestion", name: "damageLocationQuestion",
mixins: [buttonQuestionWrapperMixin],
data(){ data(){
return { return {
damageOptions: {}, damageOptions: {},
selectedDamageLocations: [] // selectedValue: []
} }
}, },
props: { props: {
@ -74,9 +76,9 @@ export default ({
buttonQuestion, buttonQuestion,
}, },
watch: { watch: {
selectedDamageLocations(selectedDamageLocations) { selectedValue(selectedValue) {
console.log("DLQ: ", selectedDamageLocations) console.log("DLQ: ", selectedValue)
this.$emit("update:modelValue", selectedDamageLocations) this.$emit("update:modelValue", selectedValue)
} }
} }
}) })

View file

@ -17,6 +17,7 @@
alertClass="alert-warning" alertClass="alert-warning"
:isDismissible="false" :isDismissible="false"
/> />
selectedDamageLocations: {{selectedDamageLocations}}
<damageLocationQuestion <damageLocationQuestion
ref="damageLocation" ref="damageLocation"
cmsWidgetName="DamageLocationQuestion" cmsWidgetName="DamageLocationQuestion"

View file

@ -177,6 +177,7 @@ export default {
// this.$emit("isCheckedChanged", emitEvent); // this.$emit("isCheckedChanged", emitEvent);
// }, // },
handleAnswerChange(e) { handleAnswerChange(e) {
console.log(e)
this.$emit("change", e); this.$emit("change", e);
}, },
}, },