fortana-co / react-dropzone-uploader

React file dropzone and uploader
https://react-dropzone-uploader.js.org/
MIT License
447 stars 183 forks source link

Submit Button #82

Open nanandn opened 4 years ago

nanandn commented 4 years ago

What's the purpose of submit button. In examples, the submit button is enabled after the upload is complete.

In my case, I want to keep adding files and upload the files when Submit button is clicked. But the default submit button is disabled. How can I programatically upload files when submit button is clicked.

coodyme commented 4 years ago

I dont know, i realy want to know what's the purpose of submit button...

frankchau93 commented 4 years ago

Is it possible to make it so that once all files are queue'd, pressing the submit button uploads all of them at once?

salientknight commented 4 years ago

submitButtonContent={null} SubmitButtonComponent={null} When passed to DropZone make the submit button go away. I believe this button is for when your entire form is just the file upload.

It also triggesr the handleSubmit function that cleans up the items in the drop zone...

artymldev commented 4 years ago

I also thought that the submit button was to trigger upload when the user had chosen files. It's very confusinbg.

I too would like files queued until the user clicks submit.

nanandn commented 4 years ago

@artymldev I used a custom "SubmitButton" component with Label Upload. set "autoUpload" props to false and in onSubmit handler, call "file.restart()" on every file that are is in "ready" state.

artymldev commented 4 years ago

I ended up doing pretty much that. Thanks!

atewari25 commented 3 years ago

@nanandn Can you share your code, I really want to enable this in my code, been stuck with this. Thanks

atewari25 commented 3 years ago

@artymldev Can you share your code, will be of great help, Thanks

nanandn commented 3 years ago

@atewari25 Something like this....

Custom submit button

const SubmitButton = (props) => {
    const { files, onSubmit } = props;

    const handleClick = React.useCallback(() => {
        if (typeof onSubmit !== "function") {
            return;
        }

        onSubmit(files.filter((f) => f.meta.status === Status.READY));
    }, [files, onSubmit]);

  return (
        <button
            type="button"
            tabIndex={0}            
            disabled={props.disabled}
            onClick={handleClick}
        >
            Upload
        </button>
    );
};

Uploader component

handleUpload = async (files) => {
        files.forEach((file) => file.restart());        
    };

<Dropzone
                    {...otherProps}
                    autoUpload={false}
                    SubmitButtonComponent={SubmitButton}
                    onSubmit={this.handleUpload}
                />