question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

multiple file input (upload)

See original GitHub issue

Is there a way to get access to the raw file array i.e. let fileSelected = this.files[0]; from a file input

 <input type="file" id="simplefile" />

Or even is there a way to get access to event.currentTarget for an onChange event?

I tried using .observe for the on change but I can only get the filename as a value.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
foxhound87commented, Apr 24, 2017

This setup is working using onChange tested on chrome:

SimpleFile.jsx

import React from 'react';
import { observer } from 'mobx-react';
import _ from 'lodash';

const onDrop = (field) => (e) => {
  const files = _.map(e.target.files); // workaround to get all files
  field.state.extra({ [field.name]: files }); // set files into extra state
  console.log('files', field.state.extra()); // get files from extra state
};

export default observer(({
  field, multiple = false,
}) => (
  <input
    multiple={multiple}
    {...field.bind({
      value: '',
      type: 'file',
      onChange: onDrop(field),
    })}
  />
));

component usage:

<SimpleFile field={form.$('myFile')} multiple />

form.state.extra() can be called everywhere to set or get additional custom form data. You can use this behavior in the meantime I implement a better solution.

0reactions
foxhound87commented, Apr 21, 2017

Implemented:

  • onDrop(e) Event Handler.
  • onDrop Field Hook.
  • file Field Prop.

Also some new example are added to the demo repo:

Read more comments on GitHub >

github_iconTop Results From Across the Web

HTML input multiple Attribute - W3Schools
Tip: For <input type="file"> : To select multiple files, hold down the CTRL or SHIFT key while selecting. Tip: For <input type="email"> :...
Read more >
How to select multiple files with <input type="file">?
You can only select 1 file per <input type="file" /> . If you want to send multiple files you will have to use...
Read more >
How to allow multiple file uploads in HTML forms.
If you want to allow a user to upload the file to your website, you need to use a file upload box, also...
Read more >
<input type="file"> - HTML: HyperText Markup Language | MDN
<input> elements with type="file" let the user choose one or more files from their device storage. Once chosen, the files can be uploaded...
Read more >
How to Select Multiple Files using HTML Input Tag
For selecting files, you must use either CTRL or SHIFT and select the number of files to be uploaded.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found