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

feat(VSelect/VAutocomplete/VCombobox): Add onChange event to return added and removed items from v-model #18054

Conversation

prashantsinghb
Copy link
Contributor

resolves #14151

Description

Added change event to return current, added and removed items from v-model

Markup:

<template>
  <v-container>
    <v-row>
      <v-col>
        <v-row><v-col>
          <v-select
            v-model="favorites"
            :items="states"
            label="Select"
            hint="Pick your favorite states"
            item-title="state"
            item-value="abbr"
            persistent-hint
            @change="onChange"
            multiple
          ></v-select>
        </v-col></v-row>
        <v-row><v-col>
          <v-autocomplete
            label="Autocomplete"
            :items="['California', 'Colorado', 'Florida', 'Georgia', 'Texas', 'Wyoming']"
            @change="onChange"
            multiple
          ></v-autocomplete>
        </v-col></v-row>
        <v-row><v-col>
          <v-combobox
            label="Combobox"
            :items="['California', 'Colorado', 'Florida', 'Georgia', 'Texas', 'Wyoming']"
            @change="onChange"
            multiple
          ></v-combobox>
        </v-col></v-row>
      </v-col>
      <v-col>
        <v-row>
          <v-col>Selection</v-col>
          <v-col v-for="(item, index) in selected" :key="index">{{item}}</v-col>
        </v-row>
        <v-row>
          <v-col>Added</v-col>
          <v-col v-for="(item, index) in added" :key="index">{{item}}</v-col>
        </v-row>
        <v-row>
          <v-col>Removed</v-col>
          <v-col v-for="(item, index) in removed" :key="index">{{item}}</v-col>
        </v-row>
      </v-col>
    </v-row>
  </v-container>
</template>

<script>
  export default {
    data () {
      return {
        favorites: [],
        states: [
          { state: 'Florida', abbr: 'FL' },
          { state: 'Georgia', abbr: 'GA' },
          { state: 'Nebraska', abbr: 'NE' },
          { state: 'California', abbr: 'CA' },
          { state: 'New York', abbr: 'NY' },
        ],
        selected: [],
        added: [],
        removed: []
      }
    },
    methods: {
      onChange(selection, added, removed){
        this.selected = selection
        this.added = added
        this.removed = removed
      }
    }
  }
</script>

@prashantsinghb prashantsinghb changed the title feat(VSelect/VAutocomplete/VCombobox): Add onChange event feat(VSelect/VAutocomplete/VCombobox): Add onChange event to return current, added and removed items from v-model Aug 15, 2023
@prashantsinghb prashantsinghb changed the title feat(VSelect/VAutocomplete/VCombobox): Add onChange event to return current, added and removed items from v-model feat(VSelect/VAutocomplete/VCombobox): Add onChange event to return added and removed items from v-model Aug 15, 2023
@KaelWD
Copy link
Member

KaelWD commented Sep 11, 2023

This just seems like unnecessary overhead for something that's trivial to do yourself.

@prashantsinghb
Copy link
Contributor Author

Closing the PR.

@prashantsinghb prashantsinghb deleted the feat/v-select_return_selected_deselected_items branch September 12, 2023 06:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants