Skip to content

Instantly share code, notes, and snippets.

@niradler
Created November 20, 2017 17:52
Show Gist options
  • Save niradler/21d0308891ce74589f579af7a7f11574 to your computer and use it in GitHub Desktop.
Save niradler/21d0308891ce74589f579af7a7f11574 to your computer and use it in GitHub Desktop.
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