Created
November 20, 2017 17:52
-
-
Save niradler/21d0308891ce74589f579af7a7f11574 to your computer and use it in GitHub Desktop.
This file contains 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
import React, {Component} from 'react'; | |
import Input from './Input'; | |
class Form extends Component { | |
constructor(props) { | |
super(props); | |
this.state = { | |
fname: '', | |
lname: '' | |
}; | |
this.fields = [ | |
{ | |
label:{text:"Email",props:{className:"bla"}}, | |
help:{text:"Email",props:{className:"bla"}}, | |
props: | |
{ | |
name: "Email", | |
type: "email", | |
}}, { | |
name: "text", | |
type: "text", | |
} | |
]; | |
} | |
componentWillMount() {} | |
handleSubmit(e) { | |
e.preventDefault(); | |
if (typeof(this.props.onSubmit) === 'function') | |
this.props.onSubmit(e); | |
} | |
render() { | |
return ( | |
<div className="Form"> | |
<form onSubmit={this.handleSubmit}> | |
{this | |
.fields | |
.map((f) => ( | |
<div className={f.InputWrapClass} key={Math.random()}> | |
{f.label ? <label {...f.label.props}>{f.label.text}</label>:''} | |
<Input {...f.props} /> | |
{f.help ? <span {...f.help.props}>{f.help.text}</span>:''} | |
</div> | |
))} | |
<button type="submit">Submit</button> | |
</form> | |
</div> | |
); | |
} | |
} | |
export default Form; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment