{"action":"created","issue":{"url":"https://api.github.com/repos/okonet/react-dropzone/issues/321","repository_url":"https://api.github.com/repos/okonet/react-dropzone","labels_url":"https://api.github.com/repos/okonet/react-dropzone/issues/321/labels{/name}","comments_url":"https://api.github.com/repos/okonet/react-dropzone/issues/321/comments","events_url":"https://api.github.com/repos/okonet/react-dropzone/issues/321/events","html_url":"https://github.com/okonet/react-dropzone/issues/321","id":200040653,"number":321,"title":"Custom validators","user":{"login":"okonet","id":11071,"avatar_url":"https://avatars.githubusercontent.com/u/11071?v=3","gravatar_id":"","url":"https://api.github.com/users/okonet","html_url":"https://github.com/okonet","followers_url":"https://api.github.com/users/okonet/followers","following_url":"https://api.github.com/users/okonet/following{/other_user}","gists_url":"https://api.github.com/users/okonet/gists{/gist_id}","starred_url":"https://api.github.com/users/okonet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/okonet/subscriptions","organizations_url":"https://api.github.com/users/okonet/orgs","repos_url":"https://api.github.com/users/okonet/repos","events_url":"https://api.github.com/users/okonet/events{/privacy}","received_events_url":"https://api.github.com/users/okonet/received_events","type":"User","site_admin":false},"labels":[{"id":132970203,"url":"https://api.github.com/repos/okonet/react-dropzone/labels/enhancement","name":"enhancement","color":"84b6eb","default":true},{"id":132970204,"url":"https://api.github.com/repos/okonet/react-dropzone/labels/help%20wanted","name":"help wanted","color":"159818","default":true},{"id":132970206,"url":"https://api.github.com/repos/okonet/react-dropzone/labels/question","name":"question","color":"cc317c","default":true}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2017-01-11T09:20:50Z","updated_at":"2017-01-11T10:27:00Z","closed_at":null,"body":"react-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.\r\n\r\nI 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:\r\n\r\n```jsx\r\nimport { validate, assertMaxFileSize, assertMinFileSize, asserFileType } from 'react-dropzone'\r\n\r\nfunction onValidate(files) {\r\n  const { acceptedFiles, rejectedFiles } = validate(assertMaxFileSize, assertMinFileSize, asserFileType)(files)\r\n  return [ acceptedFiles, rejectedFiles ]\r\n}\r\n\r\nconst MyDropZone = (props) => {\r\n  return <Dropzone onValidate={onValidate} />\r\n}\r\n```\r\n\r\nThis would allow create custom validators and react to rejections appropriately in the UI.\r\n\r\nThoughts?"},"comment":{"url":"https://api.github.com/repos/okonet/react-dropzone/issues/comments/271833090","html_url":"https://github.com/okonet/react-dropzone/issues/321#issuecomment-271833090","issue_url":"https://api.github.com/repos/okonet/react-dropzone/issues/321","id":271833090,"user":{"login":"kandros","id":4562878,"avatar_url":"https://avatars.githubusercontent.com/u/4562878?v=3","gravatar_id":"","url":"https://api.github.com/users/kandros","html_url":"https://github.com/kandros","followers_url":"https://api.github.com/users/kandros/followers","following_url":"https://api.github.com/users/kandros/following{/other_user}","gists_url":"https://api.github.com/users/kandros/gists{/gist_id}","starred_url":"https://api.github.com/users/kandros/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kandros/subscriptions","organizations_url":"https://api.github.com/users/kandros/orgs","repos_url":"https://api.github.com/users/kandros/repos","events_url":"https://api.github.com/users/kandros/events{/privacy}","received_events_url":"https://api.github.com/users/kandros/received_events","type":"User","site_admin":false},"created_at":"2017-01-11T10:27:00Z","updated_at":"2017-01-11T10:27:00Z","body":"I don't know, I believe simple validation like file-size and file-type is better as it is now, handled by the library and based on props, for more complex validation you can already handle all of them in the onDrop function, where you have access  to the files array already.\r\n\r\nThe example is not actually exposing the failure reasons.\r\n\r\nwhat showed in #257 with the reasons exported (to match rejected files with a filter function) looks more intuitive \r\n   "}}
{"actor":{"display_login":"kandros"}}