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

fix(VSelect): Do not keep null items when filtering duplicates #14464

Merged
merged 1 commit into from Dec 14, 2021

Conversation

billerby
Copy link
Contributor

@billerby billerby commented Dec 5, 2021

Description

The https://github.com/vuetifyjs/vuetify/commit/4a855cd8d940c35fc01c5a8521ff539c7491eda1 made some of our autocompletes crash on null references. This change removes any null items from the array before the check introduced by the above commit. Keeping the nulls seemed like a bad idea.

Motivation and Context

Without the fix we are not able to upgrade from vuetify 2.3.15
This resolves #14421

How Has This Been Tested?

visually

Markup:

<template>
  <v-container>
    <div id="app">
  <v-app id="inspire">
    <v-card
      class="overflow-hidden"
      color="purple lighten-1"
      dark
    >
      <v-toolbar
        flat
        color="purple"
      >
        <v-icon>mdi-account</v-icon>
        <v-toolbar-title class="font-weight-light">
          User Profile
        </v-toolbar-title>
        <v-spacer></v-spacer>
        <v-btn
          color="purple darken-3"
          fab
          small
          @click="isEditing = !isEditing"
        >
          <v-icon v-if="isEditing">
            mdi-close
          </v-icon>
          <v-icon v-else>
            mdi-pencil
          </v-icon>
        </v-btn>
      </v-toolbar>
      <v-card-text>
        <v-text-field
          :disabled="!isEditing"
          color="white"
          label="Name"
        ></v-text-field>
        <v-autocomplete
          :disabled="!isEditing"
          :items="states"
          :filter="customFilter"
          color="white"
          item-text="name"
          label="State"
        ></v-autocomplete>
      </v-card-text>
      <v-divider></v-divider>
      <v-card-actions>
        <v-spacer></v-spacer>
        <v-btn
          :disabled="!isEditing"
          color="success"
          @click="save"
        >
          Save
        </v-btn>
      </v-card-actions>
      <v-snackbar
        v-model="hasSaved"
        :timeout="2000"
        absolute
        bottom
        left
      >
        Your profile has been updated
      </v-snackbar>
    </v-card>
  </v-app>
</div>
  </v-container>
</template>

<script>
  export default {
    data: () => ({
    hasSaved: false,
      isEditing: null,
      model: null,
      states: [
        { name: 'Florida', abbr: 'FL', id: 1 },
        null,
        { name: 'Georgia', abbr: 'GA', id: 2 },
        { name: 'Nebraska', abbr: 'NE', id: 3 },
        { name: 'California', abbr: 'CA', id: 4 },
        { name: 'New York', abbr: 'NY', id: 5 },
      ],
    }),
    methods: {
    customFilter (item, queryText, itemText) {
      const textOne = item.name.toLowerCase()
      const textTwo = item.abbr.toLowerCase()
      const searchText = queryText.toLowerCase()

      return textOne.indexOf(searchText) > -1 ||
        textTwo.indexOf(searchText) > -1
    },
    save () {
      this.isEditing = !this.isEditing
      this.hasSaved = true
    },
  },
  }
</script>

Types of changes

  • [x ] Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Improvement/refactoring (non-breaking change that doesn't add any features but makes things better)

Checklist:

  • [ x] The PR title is no longer than 64 characters.
  • [ x] The PR is submitted to the correct branch (master for bug fixes and documentation updates, dev for new features and backwards compatible changes and next for non-backwards compatible changes).
  • [ x] My code follows the code style of this project.
  • I've added relevant changes to the documentation (applies to new features and breaking changes in core library)

@billerby billerby changed the title Null items should not be added to list of unique items fix (VSelect): Do not keep null items when filtering duplicates Dec 5, 2021
@billerby billerby changed the title fix (VSelect): Do not keep null items when filtering duplicates fix(VSelect): Do not keep null items when filtering duplicates Dec 5, 2021
@KaelWD KaelWD merged commit 8fd3510 into vuetifyjs:master Dec 14, 2021
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

Successfully merging this pull request may close these issues.

[Bug Report][2.6.0] Null not handled properly in v-autocomplete (and v-select)
2 participants