Wrappers for formik that simplify usage with semantic-ui-react.
Benefits:
onChange
for youvalue
(Ex: value: true
for Checkbox instead of checked
Install: npm i formik-semantic-ui
Ex:
<Form initialValues={{emailAddress:""}} onSubmit={(values, formikApi) => {
api.save(values);
formikApi.setFieldError('emailAdress', 'already in use')
}}>
<Input label="Email" name="emailAddress" />
<Button.Submit>Submit</Button.Submit>
<Button.Reset>Cancel</Button.Reset>
</Form>
Demo:
options
can be passed to component directly or through inputProps
props:
Property | Required | Default | Desc |
---|---|---|---|
name | required | formik property key checks touched , errors , and values |
|
id | optional | field_input_${count} |
used to override default id put on component and associated via label |
label | optional | undefined |
displays label on <Form.Field> |
inputProps | optional | {} |
props to be passed to matching Semantic-UI component. Ex: {type:"password"} on <Input /> |
fieldProps | optional | {} |
props passed to <Form.Field /> |
errorComponent | optional | span with class sui-error-message |
Use a component that receive a message prop (can be used also as a render prop) |
inputRef | optional | ref function to get handle to dom element (does not work on DropDown) | |
fast | optional | false | whether to use formik's FastField (beneficial for large forms) |
Produce Semantic-UI:
<Form.Field error={checks errors}>
<label />
<CONNECTED_FORMIK_COMPONENT /> /* Example <Input /> */
<span className="sui-error-message">Some error message</span>
</Form.Field>
<Form />
render={formikProps => <Form />}
handleSubmit
for Semantic UI Form onSubmit
isSubmitting
for Semantic UI Form loading
ignoreLoading
- if you wish to disconnect the Forms loading
prop from isSubmitting
<Formik />
props EXCEPT component
<Form />
Ex:
<Form
{...props}
onSubmit={handleSubmit}
loading={!props.ignoreLoading && isSubmitting}
/>
<Form.Children />
- alias for <React.Fragment>
to better show intent when using render prop
<Button {...props} type="button" />
<Button primary {...props} type="submit" />
<Button basic {...props} type="button" onClick={handleReset} />
Current:
keys
map to component name
propInput
if type is unknowntype
to Input type={type}
fieldProps
Usage:
<Form
onSubmit={this._handleSubmit}
schema={{
emailAddress: {
label: 'Email Address',
type: 'text',
value: 'justinobney@gmail.com',
},
ssn: {
label: 'SSN',
type: 'password',
fieldProps: {
width: 8,
},
},
notes: {
label: 'Notes',
type: 'textarea',
inputProps: {
rows: '6',
},
},
likes: {
label: 'Favorite Food',
type: 'dropdown',
options: [
{text: 'Pizza', value: 'pizza'},
{text: 'I am wrong', value: 'im-wrong'},
],
},
agree: {
label: 'I Agree',
type: 'checkbox',
},
}}
>
<Button.Submit>Submit</Button.Submit>
<Button.Reset>Cancel</Button.Reset>
</Form>