Created
January 14, 2017 19:20
-
-
Save mbury/3316f3242827d23281b80a644692bbdb 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 { reduxForm, Field } from 'redux-form'; | |
import { Form, Button, Label, Input } from 'semantic-ui-react'; | |
const CustomInput = ({ input, meta: { error, touched }, label, ...custom }) => ( | |
<Form.Field error={error && touched}> | |
<label htmlFor={custom.name} >{label}</label> | |
<Input id={custom.name} {...input} {...custom} /> | |
{error && touched && <Label basic color="red" pointing>{error}</Label>} | |
</Form.Field> | |
); | |
class TestForm extends Component { | |
render() { | |
const { | |
handleSubmit, | |
invalid, | |
pristine, | |
reset, | |
submitting | |
} = this.props; | |
return ( | |
<div> | |
<Form onSubmit={handleSubmit}> | |
<Field | |
name="name" | |
label={'Name'} | |
component={CustomInput} | |
/> | |
<Field | |
name="url" | |
label={'URL'} | |
component={CustomInput} | |
/> | |
<Button | |
positive | |
type="submit" | |
loading={submitting} | |
disabled={pristine || submitting || invalid} | |
> | |
Save | |
</Button> | |
<Button | |
basic | |
type="button" | |
onClick={reset} | |
disabled={pristine || submitting} | |
> | |
Reset | |
</Button> | |
</Form> | |
</div> | |
); | |
} | |
} | |
export default reduxForm({ form: 'test' })(TestForm); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment