Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FileField never updates #61

Closed
dshook opened this issue Mar 4, 2015 · 3 comments
Closed

FileField never updates #61

dshook opened this issue Mar 4, 2015 · 3 comments
Labels

Comments

@dshook
Copy link

dshook commented Mar 4, 2015

I'm using a normal File field fileupload: forms.FileField({required: false}), and when the user selects a file and the form is submitted the form files property is an empty object. There also doesn't seem to be a way to get a react reference to the field directly to get the Form value.

What I'm expecting/needing to get to:

    <input type="file" name="file" ref="fileUpload"  />
    <script>
       var fileNode = this.refs.fileUpload.getDOMNode();
       var file = fileNode.files[0];
    </script>

Just like if you were to do it through straight js/jquery;

I've noticed this is the same behavior on the all fields demo
http://insin.github.io/newforms-examples/all-fields/

If you break on line 162 inside of onSubmit, after the validate this.state.form.files is an empty object

@insin
Copy link
Owner

insin commented Mar 4, 2015

FileField needs an overhaul to support the way file inputs are actually used in JavaScript-heavy apps - the current version is still pretty much a direct port from Django, and is only usable with regular form submissions, with you handling everything on the server side.

There's a warning to that effect in the docs, but it should be added everywhere else FileField is mentioned:

Ideas for some of what needs to be done are on the Wiki:

I still haven't used file inputs in any React apps myself, nor did I get much response asking about them on the mailing list a while back, so pointers to how people are actually using them are welcome.

I'll add a warning to the other areas in the docs until I get time to revisit.

@dshook
Copy link
Author

dshook commented Mar 4, 2015

I did see that but thought I'd be able to get at the native file object some way with the current version haha. How difficult would it be to make the cleanedValue the native file object as a temporary solution?

@insin
Copy link
Owner

insin commented Mar 4, 2015

That might actually not be that difficult, a special case for FileField in Form.prototype._handleFieldEvent should do the trick.

Might just need some tweaks around some of the special cases already in place for FileField elsewhere.

Will have a look later today.

@insin insin added the Defect label Mar 5, 2015
@insin insin mentioned this issue Mar 5, 2015
Closed
16 tasks
insin added a commit that referenced this issue Mar 6, 2015
…Field

Only set form.files onChange if the input has a 'files' property

Set an array or single file based on type of FileField

Browser: retrieval of FileField data from input now falls back to data if not present in files

Related to #61
@insin insin closed this as completed Mar 6, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants