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(inputs): reset value to null instead of undefined #12373

Merged
merged 3 commits into from
Nov 3, 2020

Conversation

KaelWD
Copy link
Member

@KaelWD KaelWD commented Oct 7, 2020

Description

This fixes some inconsistencies when resetting input fields.

  • v-text-field would reset to null when clear was clicked, but undefined in a form.
  • v-select and variants, and v-file-input would reset to undefined or [] if multiple.
  • v-autocomplete and v-combobox would reset search-input to null, unless clear was clicked then it would be undefined instead

With this change these will all be null or [], allowing values to be sent as JSON without having to check for undefined first.

This is technically a breaking change if someone was relying on form.reset() to reset inputs to undefined but this is unlikely and can easily be worked around by setting the values manually afterwards.
v-select also now re-selects an item with value: null if the clear button is clicked (#4431, unit test). Again, unlikely to actually be a problem (either intended behaviour or not using both clearable and a null item) and easily worked around by implementing the clear button yourself with append-icon and @click:clear.

The consistency is worth these low-impact changes in my opinion.

Some sort of clear-value prop (#4144, #7441) would be even better, but the PR was abandoned and apparently had problems with non-falsy values.

fixes #7429

Types of changes

  • 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)

Untested outside of existing unit tests btw, might be scuffed

@KaelWD KaelWD added T: enhancement Functionality that enhances existing features C: VForm VForm C: VTextField VTextField C: VSelect VSelect C: VCombobox VCombobox C: VAutocomplete VAutocomplete labels Oct 7, 2020
@KaelWD KaelWD added this to the v2.4.0 milestone Oct 7, 2020
@KaelWD KaelWD self-assigned this Oct 7, 2020
johnleider
johnleider previously approved these changes Oct 7, 2020
Copy link

@sindilevich sindilevich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello, this is a great PR that tremendously streamlines handling inputs' data!
I thought to highlight, however, that some traces of undefined are still left unaltered. I can't tell whether they'd matter at all, but thought it'd better to point them out:

Hope it helps, and thank you.

@KaelWD
Copy link
Member Author

KaelWD commented Oct 19, 2020

Good catch, thanks.

@johnleider johnleider self-requested a review October 20, 2020 20:23
Copy link
Member

@johnleider johnleider left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's outside of this issue's scope but I think we should explore exposing the reset process so the user could set it to whatever they want.

@sindilevich
Copy link

It's outside of this issue's scope but I think we should explore exposing the reset process so the user could set it to whatever they want.

Letting user a way to control the reset value - is a great idea! Hope someone could come up with an appropriate PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C: VAutocomplete VAutocomplete C: VCombobox VCombobox C: VForm VForm C: VSelect VSelect C: VTextField VTextField T: enhancement Functionality that enhances existing features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants