google-apps-scriptgoogle-apps-for-education

Disable Submit Button if No fileupload File Chosen


I made a form for clients to upload one or more documents through five different fileuploads. I'd like to disable the submit button for the entire form unless at least one file is chosen for one of the fileuploads (doesn't matter which one).

Thanks in advance!


Solution

  • This has already been answered, at least partly. Here's the link: Form validation on fields and FileUpload

    Essentially, you make a invisible textBox.
    Then attach a trigger to the "select a file" button, that gives that textBox a value.
    You then use your standard validation tools to check that textBox for the value, and if it finds the correct value, then enable the button.

    You will also have to sort the files in doPost to see which files they have decided to upload, because if you try to run the saving of the upload on an empty slot, you will throw an error. Instead, you can use an If Statement to make sure you only try to upload true files. You can tell if a file is there or not by running e.parameter.fileUpload.name, which should return the file name if there is a file there. If there isn't, it would return "undefined". Then make the doPost only run for those files present. You can sort this out with a little Javascript.