Skip to content

feat(form-file): reset file input when value set to null or empty string #2170

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

Merged
merged 8 commits into from
Nov 14, 2018

Conversation

tmorehouse
Copy link
Member

@tmorehouse tmorehouse commented Nov 13, 2018

Description of Pull Request:

As an alternative to calling the reset() method, users can now clear the form file input by setting the v-model to null or an empty string.

The watcher checks for null and empty string and internally calls reset().

Also listens for reset events triggered by the parent form and clears the v-model

PR checklist:

What kind of change does this PR introduce? (check at least one)

  • Bugfix
  • Feature
  • Enhancement to an existing feature
  • ARIA accessibility
  • Documentation update
  • Other, please describe:

Does this PR introduce a breaking change? (check one)

  • Yes
  • No

The PR fulfills these requirements:

  • It's submitted to the dev branch, not the master branch
  • When resolving a specific issue, it's referenced in the PR's title (i.e. fixes #xxxx[,#xxxx], where "xxxx" is the issue number)
  • The PR should address only one issue or feature. If adding multiple features or fixing a bug and adding a new feature, break them into separate PRs if at all possible.
  • PR titles should following the Conventional Commits naming convention (i.e. "fix(alert): not alerting during SSR render", "docs(badge): Updated pill examples, fix typos", "chore: fix typo in docs", etc). This is very important, as the CHANGELOG is generated from these messages.

If new features/enhancement/fixes are added or changed:

  • Includes documentation updates (including updating the component's package.json for slot and event changes)
  • New/updated tests are included and passing (if required)
  • Existing test suites are passing
  • The changes have not impacted the functionality of other components or directives
  • ARIA Accessibility has been taken into consideration (does it affect screen reader users or keyboard only users? clickable items should be in the tab index, etc)

If adding a new feature, or changing the functionality of an existing feature, the PR's description above includes:

  • A convincing reason for adding this feature (to avoid wasting your time, it's best to open a suggestion issue first and wait for approval before working on it)

As an alternative to calling the `reset()` method, users can now clear the form file input by setting the v-model to null or an empty string.

The watcher checks for null and empty string and internally calls reset()
@codecov
Copy link

codecov bot commented Nov 13, 2018

Codecov Report

Merging #2170 into dev will decrease coverage by 0.06%.
The diff coverage is 0%.

Impacted file tree graph

@@           Coverage Diff            @@
##            dev    #2170      +/-   ##
========================================
- Coverage    66%   65.93%   -0.07%     
========================================
  Files       158      158              
  Lines      3000     3003       +3     
  Branches    833      835       +2     
========================================
  Hits       1980     1980              
- Misses      740      741       +1     
- Partials    280      282       +2
Impacted Files Coverage Δ
src/components/form-file/form-file.js 11.25% <0%> (-0.44%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 07bfc29...f52b350. Read the comment docs.

@@ -152,6 +156,11 @@ export default {
} else {
this.$emit('input', newVal)
}
},
value (newVal) {
if (newVal === null || newVal === '') {
Copy link
Member

Choose a reason for hiding this comment

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

What is about empty arrays when multiple is enabled?
Is there any particular reason this isn't taken into account here?

If not, I would suggest to change the check to:

if (
  (this.multiple && Array.isArray(newVal) && newVal.length === 0) ||
  (!this.multiple && (newVal === null || newVal === ''))
) {
  ...
}

Copy link
Member Author

@tmorehouse tmorehouse Nov 13, 2018

Choose a reason for hiding this comment

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

i thought about that (and originall had it typed in similar), but figured null is ideally the best (and it's the default intenally). although it might be a good addition, just in case. feel free to push a pr to this branch :)

Copy link
Member Author

Choose a reason for hiding this comment

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

actually, I think you could skip the check for multiple and just check of it is an array that is zero length, or null or empty string. no need to make the tests too complex.

Copy link
Member Author

Choose a reason for hiding this comment

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

also, when the input is reset, we send out an update to the v-model to update to either an empty array (in multiple mode) or null if in single mode

Copy link
Member Author

Choose a reason for hiding this comment

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

for the isArray test, we could pull in isArray from utils/array.js, as it helps with minification.

Copy link
Member

Choose a reason for hiding this comment

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

@tmorehouse Wouldn't it be easier if you apply the changes? :)

Copy link
Member Author

Choose a reason for hiding this comment

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

lol, I was out getting groceries..

@tmorehouse
Copy link
Member Author

I'll need to redo the tests using vue-test-utils at a later date, when I make some additional general input changes.

@tmorehouse tmorehouse merged commit ab44375 into dev Nov 14, 2018
@tmorehouse tmorehouse deleted the tmorehouse/form-file branch November 14, 2018 00:54
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.

2 participants