Introduction to FormEngine
In the world of React development, managing forms can often become a complex task. Enter Formik, a beloved open-source library that simplifies form management by handling state, validation, and submission seamlessly. However, if you’re looking for even more features and capabilities, look no further than FormEngine. This powerful library not only matches Formik’s capabilities but also extends them, offering advanced features for form management. In this article, we’ll explore how to integrate Formik with FormEngine, allowing you to leverage the strengths of both libraries. Whether you want to reuse existing code or prefer the familiar Formik setup, this guide will help you get started. Let’s omit some boilerplate code and highlight only important things.Code changes
Highlighted lines indicate the ones that need attention. If the file is created for the first time, then any modified lines are not marked in it. If the file is modified within the tutorial, then the modified, added, and deleted lines are marked in it as follows.Getting Started with FormEngine and Formik
To kick off, create a new React project and install the necessary dependencies. Open your terminal and run the following commands:Initializing the FormEngine Designer
Next, replace the contents ofApp.tsx with the following code to set up FormEngine’s Designer:
src/App.tsx

Creating a Simple Booking Form
Let’s create a simple booking form with the following fields:- Customer’s Full Name
- Check-in Date
- Total Number of Guests
fullName, checkinDate, guestCount.

Integrating Formik with Your Booking Form
If you have an existing form implemented with Formik using hooks, you can easily integrate it with FormEngine. Here’s how you can set up thesrc/useBookingForm.ts:
Bridging FormEngine and Formik
Firstly, we need to change thetarget for TypeScript (because we are using iteration on object properties):
tsconfig.json
App.tsx file, you can just
replace the contents with the code below (major changes are highlighted):
src/App.tsx


Leveraging Yup for Validation
Yup is a powerful validation library that works seamlessly with Formik and is recommended by its team. To enhance our validation process, we can define Yup validators and integrate them into our FormEngine setup. Let’s rewrite our validation using Yup and use it. We are going to bind Yup validators directly to FormEngine native validation, but we also can use it inside Formik form definition as shown above. Create avalidators.ts file:
src/validators.ts
toFormEngineValidate which will be the bridge between two libraries.
Please notice validation is now done by FormEngine and we sync errors back to Formik.
Then, update your App.tsx to utilize these validators within FormEngine (major changes are highlighted):
src/App.tsx

useBookingForm.ts
