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

Update FileDropzone API #678

Merged
merged 13 commits into from
Feb 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 9 additions & 14 deletions docs/validation.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,24 @@ For more details see the [MDN accept attribute reference](https://developer.mozi

## Custom validation

Both components provide callback arguments with which you may implement custom validation of chosen files.
Both `<FileUpload>` and `<FileDropzone>` components accept the `@filter` argument with which you may implement custom validation of chosen files.

`<FileUpload>` may be passed `@onSelect` and `<FileDropzone>` may be passed `@onDrop`.

These are called *after* files have been chosen and *before* `@onFileAdd` is called by the queue.

To implement validation, you may (optionally) return a subset of files from these callbacks to restrict which files are queued for upload.
This are called *after* files have been chosen and *before* `fileAdded` is called by the queue.

See the example below where the same validation callback is used for both selection methods.

Commonly validated file properties are `type`, `name` and `size`. For more details see the [MDN File reference](https://developer.mozilla.org/en-US/docs/Web/API/File).

```hbs
<FileDropzone
@name="photos"
@onDrop={{this.validateFiles}}
as |dropzone queue|
@queue={{queue}}
@filter={{this.validateFile}}
as |dropzone|
>
...
<FileUpload
@name="photos"
@onSelect={{this.validateFiles}}
@onFileAdd={{perform this.uploadImage}}
@queue={{queue}}
@filter={{this.validateFile}}
/>
...
</FileDropzone>
Expand All @@ -50,8 +45,8 @@ const allowedTypes = [

export default class ExampleComponent extends Component {
...
validateFiles(files) {
return files.filter((file) => allowedTypes.includes(file.type));
validateFile(file) {
return allowedTypes.includes(file.type);
}
}
```
7 changes: 1 addition & 6 deletions ember-file-upload/addon/components/file-dropzone.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,7 @@
dragover=this.didDragOver
drop=this.didDrop
}}
{{update-queue
this.queue
multiple=@multiple
disabled=@disabled
onFileAdd=@onFileAdd
}}
{{this.bindListeners}}
>
{{yield
(hash supported=this.supported active=this.active)
Expand Down
301 changes: 0 additions & 301 deletions ember-file-upload/addon/components/file-dropzone.js

This file was deleted.

Loading