Custom validators
See original GitHub issuereact-dropzone provides some simple validation out of the box like accept, minSize and maxSize but it lacks rejection reason (#257 and #319) so it’s impossible to react to this rejection without the duplicating the validations in the user’s component’s code.
I have been thinking about implementing some kind of custom validator functions that you could then compose. Each such validator function should have a generic API. Something like this:
import { validate, assertMaxFileSize, assertMinFileSize, asserFileType } from 'react-dropzone'
function onValidate(files) {
const { acceptedFiles, rejectedFiles } = validate(assertMaxFileSize, assertMinFileSize, asserFileType)(files)
return [ acceptedFiles, rejectedFiles ]
}
const MyDropZone = (props) => {
return <Dropzone onValidate={onValidate} />
}
This would allow create custom validators and react to rejections appropriately in the UI.
Thoughts?
Issue Analytics
- State:
- Created 7 years ago
- Reactions:5
- Comments:20
Top Results From Across the Web
Angular Custom Form Validators: Complete Guide
a custom validator is a function that validates the value of a form field according to a business rule, such as form example...
Read more >Validating form input - Angular
A cross-field validator is a custom validator that compares the values of different fields in a form and accepts or rejects them in...
Read more >Custom Validators in Angular | Articles by thoughtram
Angular comes with a subset of built-in validators out of the box. We can apply them either declaratively as directives on elements in...
Read more >The best way to implement custom validators - Angular inDepth
Learning best practices on how to build your custom validator in Angular by reverse engineering the built-in Angular validators.
Read more >Custom Validators — FluentValidation documentation
There are several ways to create a custom, reusable validator. The recommended way is to make use of the Predicate Validator to write...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

here’s some boilerplate I wrote to validate image dimensions in case anyone needs it:
I’ve updated my answer using FileReader, sorry for some nastiness in here: