-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Conversation
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 Report
@@ 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
Continue to review full report at Codecov.
|
@@ -152,6 +156,11 @@ export default { | |||
} else { | |||
this.$emit('input', newVal) | |||
} | |||
}, | |||
value (newVal) { | |||
if (newVal === null || newVal === '') { |
There was a problem hiding this comment.
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 === ''))
) {
...
}
There was a problem hiding this comment.
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 :)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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? :)
There was a problem hiding this comment.
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..
test for empty array on value
I'll need to redo the tests using vue-test-utils at a later date, when I make some additional general input changes. |
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)
Does this PR introduce a breaking change? (check one)
The PR fulfills these requirements:
dev
branch, not themaster
branchfixes #xxxx[,#xxxx]
, where "xxxx" is the issue number)CHANGELOG
is generated from these messages.If new features/enhancement/fixes are added or changed:
package.json
for slot and event changes)If adding a new feature, or changing the functionality of an existing feature, the PR's description above includes: