Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Add third parameter "removedOption" to @select event if previously a option was selected #1801

Open
mediaessenz opened this issue Oct 10, 2024 · 0 comments

Comments

@mediaessenz
Copy link

mediaessenz commented Oct 10, 2024

I'm currently facing the problem, that I have several select boxes which options should depend on each other.

If an option is selected in box A it should disapear in box B and the other way around.

I got it working by using the @remove and @select events – as long as the user is deselecting the previous selection and make a new selection afterward.

But if the user changes his selection in one step, no @remove event is currently fired and a @change event is not available as well.

I got it working finally with a construct like so, but it feels not realy good ...:

<template>
<multiselect v-for="(selection, index) in selections" v-model="selection" :key="index" @open="storeLastSelection(index)" @select="selection" @remove="remove" :options="selection ? [selection].concat(options) : options">
</template>
<script setup>
const selections = ref([ref(''),ref('')]);
const options = ref(['option1', 'option2', 'option3']);
const lastSelection = ref(null);
const storeLastSelection = (index) => {
    lastSelection.value = selections.value[index];
}
const select = (value) => {
   options.value.splice(options.value.findIndex((option) => option ===  value), 1);
   if (lastSelection.value) remove(lastSelection.value);
}
const remove = (value) => {
    options.value.push(value);
    lastSelection.value = null;
}
</script>

It would be much easier, if there would be a third parameter "removedOption" given to the @select event if previously a option was selected. This would not break the current behaviour and could imo be realized easily.

@mediaessenz mediaessenz changed the title [Feature] Fire @remove event before @select if a selection was changed [Feature] Add third parameter "removedOption" to @select event if previously a option was selected Oct 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant