Skip to content

Commit 53888e8

Browse files
authored
Merge pull request #84 from easeq/master
v0.6.0
2 parents 29f65b1 + 3d900ac commit 53888e8

File tree

6 files changed

+34
-33
lines changed

6 files changed

+34
-33
lines changed

package-lock.json

Lines changed: 20 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@flipbyte/formik-json",
3-
"version": "0.5.1",
3+
"version": "0.6.0",
44
"description": "formik-json is a wrapper for Formik to easily create forms using JSON / Javascript Object for defining the elements",
55
"main": "lib/index.js",
66
"module": "es/index.js",
@@ -29,7 +29,7 @@
2929
"@flipbyte/when-condition": "^0.6.0",
3030
"@flipbyte/yup-schema": "^0.1.5",
3131
"codemirror": "^5.41.0",
32-
"formik": "^1.5.2",
32+
"formik": "^2.1.4",
3333
"react-autosuggest": "^9.4.3",
3434
"react-codemirror2": "^7.0.0",
3535
"react-dropzone": "^10.2.1",

src/Container/Form.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,21 @@ import React from 'react';
33
import Element from '../Element';
44
import { getName } from '../utils';
55
import PropTypes from 'prop-types';
6+
import { Form as FormikDOMForm } from 'formik';
67

7-
const Form = ({ config, formik }) => {
8+
const Form = ({ config }) => {
89
const { name: containerName = '', elements, htmlClass = 'form-horizontal', comment, commentClass = 'text-muted d-block mb-3' } = config;
9-
const { handleSubmit, handleReset } = formik;
1010

1111
return(
12-
<form className={ htmlClass } onSubmit={ handleSubmit } onReset={ handleReset }>
12+
<FormikDOMForm className={ htmlClass }>
1313
{ comment && <small className={ commentClass }>{ comment }</small> }
1414
{ _.map(elements, ({ name, ...config }, key) => (
1515
<Element
1616
key={ key }
1717
config={{ ...config, name: getName(config.type, name, containerName) }}
1818
/>
1919
))}
20-
</form>
20+
</FormikDOMForm>
2121
);
2222
}
2323

src/Element.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,5 +83,6 @@ export default connect(
8383
&& shallowequal(config, nextProps.config)
8484
&& formik.initialValues === nextProps.formik.initialValues
8585
&& formik.isValidating === nextProps.formik.isValidating
86+
&& formik.isSubmitting === nextProps.formik.isSubmitting
8687
))
8788
);

src/ErrorManager.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import _ from 'lodash';
22
import React, { useState } from 'react';
3-
import { connect } from 'formik';
3+
import { useFormikContext } from 'formik';
44

55
/**
66
* Error manager component that displays error only when it's right
@@ -20,9 +20,10 @@ import { connect } from 'formik';
2020
* @param {object} formik
2121
* @param {function} children
2222
*/
23-
const ErrorManager = ({ name, formik, children }) => {
23+
const ErrorManager = ({ name, children }) => {
2424
// Set submitCount on initial mount.
25-
const { submitCount: formikSubmitCount, isSubmitting, errors, touched } = formik;
25+
const formik = useFormikContext();
26+
const { submitCount: formikSubmitCount, isSubmitting, errors, touched } = useFormikContext();
2627
const [ submitCount ] = useState(isSubmitting ? formikSubmitCount - 1 : formikSubmitCount);
2728
const isTouched = _.get(touched, name);
2829
const errorMessage = _.get(errors, name);
@@ -31,4 +32,4 @@ const ErrorManager = ({ name, formik, children }) => {
3132
return children(error);
3233
};
3334

34-
export default connect(ErrorManager);
35+
export default ErrorManager;

src/Form.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const Form = React.forwardRef(({ schema, onUpdate = () => {}, initialValues = {}
3535
}, [ schema ]);
3636

3737
/**
38-
* Everytime the schema changes re-initialize validationSchema
38+
* Everytime the schema changes, re-initialize validationSchema
3939
*
4040
* This is has to be done everytime schema changes because,
4141
* certain cases may involve dynamically changing form fields based on
@@ -54,7 +54,7 @@ const Form = React.forwardRef(({ schema, onUpdate = () => {}, initialValues = {}
5454
<SchemaProvider value={{ validationSchema, schema }}>
5555
<Formik
5656
{ ...formProps }
57-
ref={ ref }
57+
innerRef={ ref }
5858
render={(props) => (
5959
<FormikForm
6060
onUpdate={ onUpdate }

0 commit comments

Comments
 (0)