Created
September 23, 2016 17:50
-
-
Save orangewolf/40c628ba72a7defbe659b2937e2dfbdd to your computer and use it in GitHub Desktop.
Formsy File Upload
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // in render return | |
| <div> | |
| <Formsy.Form ref="form" | |
| onValidSubmit={this.onSubmit} | |
| onValid={this.props.enableSubmit} | |
| className="" | |
| onInvalid={this.props.disableSubmit} | |
| onChange={this.props.onChange}> | |
| <FormsyFile | |
| id="avatar" | |
| name="avatar" | |
| /> | |
| </Formsy.Form> | |
| </div> | |
| // In onSubmit | |
| onSubmit function(form_data) { | |
| ... //setup | |
| var avatarFile = document.getElementById('avatar').files[0]; | |
| form_data.append('avatar', avatarFile); | |
| this.serverRequest = $.ajax({ | |
| dataType: "json", | |
| method: "POST", | |
| url: url, | |
| data: form_data, | |
| headers: headers, | |
| success: this.submitted, | |
| error: this.errored | |
| }); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment