Skip to content

Instantly share code, notes, and snippets.

@mbury
Created January 14, 2017 19:20
Show Gist options
  • Save mbury/3316f3242827d23281b80a644692bbdb to your computer and use it in GitHub Desktop.
Save mbury/3316f3242827d23281b80a644692bbdb to your computer and use it in GitHub Desktop.
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