Search code examples
javascripthtmlreactjsfilepond

Disable form submit while file is loading FilePond


I am using FilePond for image file in my form. I want form submit to be disabled while image/file is loading. and reenabled once image is loaded.

I searched their docs but couldn't find what might help

This when Submit button should be disabled

enter image description here


Solution

  • By using these callbacks, you can disable the submit button while the files load.

    onaddfilestart(file) – Started file load

    onaddfileprogress(file, progress) Made progress loading a file

    onaddfile(error, file) If no error, file has been successfully loaded.

    function App() {
      const [files, setFiles] = useState([]);
      const [loading,setLoading] = useState(false);
    
      return (
        <div className="App">
          <FilePond
            files={files}
            allowReorder={true}
            allowMultiple={true}
            onupdatefiles={setFiles}
            onaddfilestart={()=> setLoading(true)}
            onaddfile={()=> setLoading(false)}
          />
          <button disabled={loading}>Submit</button>
        </div>
      );
    }
    

    reference - https://pqina.nl/filepond/docs/api/instance/properties/#callbacks