1
0
mirror of https://github.com/ascribe/onion.git synced 2024-12-22 09:23:13 +01:00

fixed form mixin

This commit is contained in:
ddejongh 2015-06-02 18:16:18 +02:00
parent 95c199bed6
commit 82d14b30fc

View File

@ -18,20 +18,24 @@ export const FormMixin = {
this.setState({submitted: true});
fetch
.post(this.url(), { body: this.getFormData() })
.then(response => { this.props.onRequestHide(); })
.then(response => { this.props.handleSuccess(); })
.catch(this.handleError);
},
handleError(err){
if (err.json) {
for (var input in errors){
for (var input in err.json.errors){
if (this.refs && this.refs[input] && this.refs[input].state) {
this.refs[input].setAlerts(errors[input]);
this.refs[input].setAlerts( err.json.errors[input]);
} else {
this.setState({errors: this.state.errors.concat(errors[input])});
this.setState({errors: this.state.errors.concat(err.json.errors[input])});
}
}
}
else{
this.setState({errors: ['Something went wrong, please try again later"']});
}
this.setState({submitted: false});
},
getBitcoinIds(){
@ -48,15 +52,12 @@ export const FormMixin = {
render(){
let alert = null;
if (this.state.status >= 500){
alert = <AlertDismissable error="Something went wrong, please try again later"/>;
}
if (this.state.errors.length > 0){
alert = this.state.errors.map(
function(error) {
return <AlertDismissable error={error} key={error}/>;
}.bind(this)
);
function(error) {
return <AlertDismissable error={error} key={error}/>;
}.bind(this)
);
}
return (
<div>