-
Notifications
You must be signed in to change notification settings - Fork 436
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
What is the best way to include a file upload? #126
Comments
Hi @jcapogna, That is an excellent question :-) I have not tried this, though I believe there are some events you can use? I think onChange will trigger on a normal FileInput var MyFileInput = React.createClass({
onInputChange: function (event) {
// Verify that file is correct via the event
this.setValue(true);
// Or if not valid
this.setValue(false);
},
render: function () {
return <input type="file" onChange={this.onInputChange}/>
}
}); And then just validate with: <MyFileInput validations="isTrue"/> You think that would work? |
That would work if I was submitting the HTML form directly. I am using the Formsy 'onSubmit' handler and then making an ajax call with the 'data' value passed to the onSubmit handler. The value you get from the file input is a fake path. For example, I selected |
Hi again @jcapogna. I believe you should be able to just store the "files" property from the input, instead of its "value" property. Check out this article: |
Closing this, hopefully it worked out :-) |
Thanks @christianalfoni This part of my project got pushed back and I still haven't gotten to it yet. Hopefully I'll be working in this again in the next month or so. I'll let you know if I run into any problems. |
Okay, cool, good luck! :-) |
Can we re-open this plz? I have essentially the same issue and am also getting hung up on the C:/fakepath/xyz Code snippet:
See attached. Note both the: and the possibly (but unlikely) related: I'm not attaching the C:\fakepath - not even on a Windows machine. I would guess it buried somewhere in the formsy code? |
@colinmccann In FRC, there is a File component. You should use that instead! See release notes for 0.4.0 for a bit more detail. The |
Hot damn, that is perfect. Thanks! |
Is there a best practice for including a file upload as part of a Formsy form?
The best idea I've come up with so far is to use FileReader to read the file contents into the input element's value. This is a bit annoying considering that a file upload is really simple with a basic HTML form.
The text was updated successfully, but these errors were encountered: