KarimMokhtar / react-drag-drop-files

Light and simple Reactjs drag and drop files library to use with very flexible options to change, so you put whatever the design you want for your drop-area. Users can drag and drop or even select the file anywhere in the window.
MIT License
245 stars 86 forks source link

If the input is required and we use drag and drop to upload the file, then on form submit, it says field is required. #123

Open SciSaif opened 1 year ago

SciSaif commented 1 year ago

If the input is required and we use drag and drop to upload the file, then on form submit, it says field is required even if the file is uploaded, so it doesn't let me submit. right now I am handling the required part manually.

jpiazzal commented 7 months ago

I have the same problem too, is there a way to avoid this problem?

I would avoid to add required as a state if possible.

The code is the same as in the example, i just added the field required:

import React, { useState } from "react";
import { FileUploader } from "react-drag-drop-files";

const fileTypes = ["JPG", "PNG", "GIF"];

function DragDrop() {
  const [file, setFile] = useState(null);
  const handleChange = (file) => {
    setFile(file);
  };
  return (
    <FileUploader handleChange={handleChange} name="file" types={fileTypes} required />
  );
}

export default DragDrop;
MariusMez commented 5 months ago

Hi, same issue here, wondering if anybody has found a way to deal with this?