forked from mui/material-ui
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request mui#771 from dmtrKovalenko/feature/form-example
Feature/form example
- Loading branch information
Showing
8 changed files
with
148 additions
and
46 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import React from 'react'; | ||
import { DatePicker } from 'material-ui-pickers'; | ||
import { Formik, Form, Field } from 'formik'; | ||
import Code from '_shared/Code'; | ||
import Grid from '@material-ui/core/Grid'; | ||
|
||
const DatePickerField = ({ field, form, ...other }) => { | ||
const currentError = form.errors[field.name]; | ||
return ( | ||
<DatePicker | ||
keyboard | ||
clearable | ||
disablePast | ||
name={field.name} | ||
value={field.value} | ||
format="dd/MM/yyyy" | ||
helperText={currentError} | ||
error={Boolean(currentError)} | ||
onError={(_, error) => form.setFieldError(field.name, error)} | ||
onChange={date => form.setFieldValue(field.name, date, true)} | ||
mask={value => | ||
value ? [/\d/, /\d/, '/', /\d/, /\d/, '/', /\d/, /\d/, /\d/, /\d/] : [] | ||
} | ||
{...other} | ||
/> | ||
); | ||
}; | ||
|
||
const FormikExample = () => { | ||
return ( | ||
<Formik initialValues={{ date: new Date() }}> | ||
{({ values, errors }) => ( | ||
<Form> | ||
<Grid container> | ||
<Grid item container justify="center" xs={12}> | ||
<div className="picker"> | ||
<Field name="date" component={DatePickerField} /> | ||
</div> | ||
</Grid> | ||
|
||
<Grid item xs={12} sm={12} style={{ margin: '24px' }}> | ||
<Code text={JSON.stringify({ errors, values }, null, 2)} /> | ||
</Grid> | ||
</Grid> | ||
</Form> | ||
)} | ||
</Formik> | ||
); | ||
}; | ||
|
||
export default FormikExample; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import React from 'react'; | ||
import SourcablePanel from '_shared/SourcablePanel'; | ||
import { Typography } from '@material-ui/core'; | ||
|
||
const Formik = () => ( | ||
<div> | ||
<Typography variant="h2" gutterBottom> | ||
Integration to form | ||
</Typography> | ||
|
||
<Typography variant="body1" gutterBottom> | ||
We are providing inbound validating dates and triggering date's on accept. | ||
And also there are quite a lot ways to submit the date, so we cannot | ||
provide the event for onChange handler. | ||
</Typography> | ||
|
||
<SourcablePanel | ||
title="Formik integration" | ||
sourceFile="Guides/Formik.example.jsx" | ||
description={ | ||
<Typography variant="body1" gutterBottom> | ||
Here is example of how to use material-ui-pickers with formik | ||
</Typography> | ||
} | ||
/> | ||
</div> | ||
); | ||
|
||
export default Formik; |
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
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
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
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