Skip to content

Instantly share code, notes, and snippets.

@Kotoriii
Last active July 19, 2017 13:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Kotoriii/cecf942e2f15899a83be6686a9cae228 to your computer and use it in GitHub Desktop.
Save Kotoriii/cecf942e2f15899a83be6686a9cae228 to your computer and use it in GitHub Desktop.
React Multistep Form State Question
var formData = {};
class FormStep1 extends Component {
constructor(props) {
super(props);
this.state = {
phone: "",
firstname: "",
lastname: "",
disabled: false,
successIsVisible: false
}
this.handleSubmit = this.handleSubmit.bind(this);
}
handleChange(name, value){
let state = this.state;
state[name] = value;
this.setState({state});
}
handleSubmit(e, message) {
this.setState({
phone: "",
firstname: "",
lastname: "",
disabled: true,
successIsVisible: true
});
}
render() {
var formBody;
if (this.props.visible) {
formBody =
<div>
<form role="form" id="phoneForm" onSubmit={this.handleSubmit} className='row'>
<div className="col-md-12">
<div className='row'>
<div className="col-md-3">
<div className='form-group'>
<label htmlFor="phone">Phone</label><br />
<input id="phone" className="form-control" placeholder="Your Phone" onChange={this.handleChange.bind(this, 'phone')} name="phone" value={this.state.phone} />
</div>
</div>
</div>
</div>
<div className="col-md-12">
<div className='row'>
<div className="col-md-3">
<div className='form-group'>
<label htmlFor="firstname">Name</label><br />
<input id="firstname" className="form-control" placeholder="Your first name" onChange={this.handleChange.bind(this, 'firstname')} name="firstname" value={this.state.firstname} />
</div>
</div>
<div className="col-md-3">
<div className='form-group'>
<label htmlFor="lastname">&nbsp;</label><br />
<input id="lastname" className="form-control" placeholder="Your last name" onChange={this.handleChange.bind(this, 'lastname')} name="lastname" value={this.state.lastname} />
</div>
</div>
</div>
</div>
<div className="col-md-12">
<div className='row'>
<div className="col-md-3">
<button className="btn btn-green btn-block" id="btnsubmit" onSubmit={this.handleSubmit} disabled={this.state.disabled} type="submit">Vermittlung starten!</button>
</div>
</div>
</div>
</form>
<FormStep2 visible={this.state.successIsVisible} />
</div>
}
return (
<div>
<CSSTransitionGroup
transitionName="success"
transitionEnterTimeout={500}
transitionLeaveTimeout={300}>
{formBody}
</CSSTransitionGroup>
</div>
);
}
}
export default FormStep1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment