gcanti / tcomb-form

Forms library for react
https://gcanti.github.io/tcomb-form
MIT License
1.16k stars 136 forks source link

Multiple files upload #365

Open karlguillotte opened 7 years ago

karlguillotte commented 7 years ago

I need to setup a form to post multiple files. I followed instruction from #112 and it is working well for one File.

Version

Should get a list of files.

Actual behaviour

I am getting null.

Steps to reproduce

So, here is my type

const Uploads = t.struct({
    files: t.list(t.form.File)
})

Because, I still want to use the html input and not an array, my options are

const options = {
        label: 'Step 2. Uploads',
        fields: {
            files: {
                factory: t.form.Textbox,
                type: 'file',
                attrs: {
                    multiple: true,
                },
                help: 'Add a photo to help tell your story.',
            }
        }
    }

Everything is fine until I call getValue on the form, I get null.

It returns a File with the type below.

const Uploads = t.struct({
    files: t.form.File
})

Any way to get an array of files? For input[type="file"] the onChange only send the first file and the list is available at input.files.

Thanks for your awesome tool!

karlguillotte commented 7 years ago

Probably the source of my issue: https://github.com/gcanti/tcomb-form-templates-semantic/blob/master/src/textbox.js#L27