We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
So basically file validation runs with empty files list producing "is not a file" error.
Any piece of advice would be highly appreciated.
<Field component={FieldUploadFile} type="file" name="attachments" label={<FormattedMessage id={messageIds['entity.ticket.field.attachments']} />} validate={[file({ allowBlank: true, maxFiles: 10, maxSize: '1 MB' })]} />
export function FieldUploadFileBase(props: IProps) { const [attachments, setAttachments] = React.useState<File[]>([]); const handleFileDrop = React.useCallback( (item: any, monitor: DropTargetMonitor) => { if (monitor) { const files = monitor.getItem().files; setAttachments(attachments.concat(files)); } }, [attachments], ); const handleFileSelect = React.useCallback((e: React.ChangeEvent<HTMLInputElement>) => { if (e.target.files) { const selectedFiles = Array.from(e.target.files); setAttachments(attachments.concat(selectedFiles)); } }, [attachments]); const onRemoveFile: AttachmentProps['onRemoveFile'] = (fileToRemove) => { setAttachments(attachments.filter((attachment) => attachment !== fileToRemove)); }; React.useEffect(() => { props.input.onChange(attachments); }, [attachments]); return ( <FormControl fullWidth> <Box marginBottom={3}> <AttachmentTargetBox onDrop={handleFileDrop} handleFileSelect={handleFileSelect} /> </Box> <AttachmentsList files={attachments} onRemoveFile={onRemoveFile} /> <p>{props.meta.error}</p> </FormControl> ); }
The text was updated successfully, but these errors were encountered:
Nor
<Field validate={[file({ allowBlank: true })]} />
neither
<Field validate={[file({ minFiles: 0 })]} />
helps
Sorry, something went wrong.
Found a workaround:
props.input.onChange(attachments.length > 0 ? attachments : undefined);
but IMO lib has to handle "empty files list" case as well
No branches or pull requests
So basically file validation runs with empty files list producing "is not a file" error.
Any piece of advice would be highly appreciated.
Field:
FieldUploadFile:
The text was updated successfully, but these errors were encountered: