formik-wizard-form | Build multi step forms using Formik with ease | Form library
kandi X-RAY | formik-wizard-form Summary
kandi X-RAY | formik-wizard-form Summary
Formik Wizard Form is stepper form component built over Formik (the most famous form library in react world). Now create your form wizards in a nice and declarative way.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- header section header
- A feature of a feature .
formik-wizard-form Key Features
formik-wizard-form Examples and Code Snippets
Community Discussions
Trending Discussions on formik-wizard-form
QUESTION
I'm building an app that will need a complex form generation (from json/js object).
Here's an example of what I'm building: https://codesandbox.io/s/formik-form-wizard-test-vcj1t
My problem is the following:
all the input fields lose focus on every value change
The folder structure of the CodeSandbox project is the following (for easier code comprehension):
./src
:
App.js
- main file with all the form generation (generateWizardSteps
is the main function that does all the generation).formSetup.js
- that's an object that defined form configuration. From objects like this I need to build dynamic forms. This object has the array ofpages
(these are the steps of the wizard), and eachpage
has an array offields
(like input, select, checkbox etc). In its turn, eachfield
hasprops
property.props
is what I pass to the React component as props.formComponents.js
- this file contains all the form field React components that I use for generating my forms.decorateWithFormik.js
- this file is just to makeApp.js
a bit smaller. It's just theuseFormik
decorator.
The form is built using the formik library. Also, as I need a wizard-like form, I've found a nice library for it: formik-wizard-form.
I've looked through the stackoverflow questions on similar topics but couldn't find something that could fit my needs. Many questions/answers are about the problem with dynamic key
props, but mine are static as far as I can tell (they all are taken from the initial formSetup
object).
Another thing that I've noticed is that my form gets re-rendered on every value change, but I'm not sure if this is a problem at all.
Could you help me to figure out what the problem is, why does it happend and how to make my form fields not lose focus?
...ANSWER
Answered 2020-Mar-03 at 20:29Solved the issue
I've removed all the possible component creation code and moved everything inside the component
props of the Step
component provided by the formik-wizard-form
library.
Here's my working solution: https://codesandbox.io/s/formik-form-wizard-test-lz3x7 (hope this will help somebody)
Many thanks to everyone in the comments section!
Main insights:
Losing focus means that the component
unmounts and remounts
every time.This unmounting/remounting behaviour on every change was caused by the creation of components inside the
render
function of another component. Consequently, on every re-render the input components were created anew.
My final working code:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install formik-wizard-form
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page