MSK Institute LogoMSK.Institute
HomeCourses
Book Free Demo➔Sign In
Free Demo➔
MSK Institute LogoMSK.Institute

Leading computer training academy in Shikohabad for software engineering, Python, web development, and digital literacy.

ISO 9001:2015 Certified Center
Follow & Connect
4.9

Programs & Admissions

  • All CoursesCatalog
  • Learning PathsRoadmaps
  • Student ProjectsShowcase
  • Live Classes & ScheduleLive
  • Upcoming Batches
  • Campuses & LocationsHub
  • Verify Certificates
  • Book Free Demo Class

Resources & Tools

  • Free Online Mock TestsAll Tests
  • NIELIT CCC Mock TestFree
  • Course & Career FinderQuiz
  • Study Material Hub
  • All MSK ToolsHub
  • Keyboard ShortcutsNew
  • TypeQuest Speed LabTyping
  • MSK Code PlaygroundCode
  • Interactive Tutorials
  • Quick Cheatsheets

Institute & Contact

  • About MSK Institute
  • Careers & InternshipsHiring
  • Publications & Blogs
  • Gali No. 3, Near Gyan Jyoti Public School,
    Adarsh Nagar, Shikohabad, Uttar Pradesh 283135
  • +91 83930 42166
  • mskshikohabad@gmail.com
  • Hours:Mon – Sat: 8:00 AM – 7:00 PM | Sun: 10:00 AM – 2:00 PM
  • 4.9 ★(38 Google Reviews)
© 2026 MSK Institute. All rights reserved.•Privacy Policy•Terms of Service•Disclaimer•Contact Us

Shikohabad's Leading Computer & Coding Academy

Home
Courses
Live
Material
Multi-Step Wizards and Dynamic Schema Validation with Yup0%
Study Materials
React.js for AdvancedProgress 0%
1.1Control Props and Inversion of Control Pattern1.2State Reducer Pattern in Advanced React1.3Prop Getters and Flexible Design Systems1.4Headless UI Architecture and Accessibility Primitives
12.1Formik Architecture and Field Arrays12.2Multi-Step Wizards and Dynamic Schema Validation with Yup12.3Custom Form Controls with useField12.4High-Performance Form Optimization Comparison
HomeTutorialsReact.js for AdvancedMulti-Step Wizards and Dynamic Schema Validation with Yup
Custom Form Controls with useField

Multi-Step Wizards and Dynamic Schema Validation with Yup

Beginner12 min read•Updated: 2026-11-18•By Er. Sumit Kumar (MSK Institute)
Study MaterialsCheatsheet

Enterprise onboarding, loan applications, and configuration setups frequently span multi-step wizard flows. Managing state across steps, validating only the fields relevant to the current active step, and supporting conditional branches based on previous answers requires advanced Formik and Yup orchestration.


1. Multi-Step Wizard Architecture

A production multi-step wizard must satisfy three criteria:

  1. 1
    Preserved Unified State: State from Step 1 must persist when moving to Step 2 and Step 3 without submitting premature data to the server.
  2. 2
    Step-Specific Validation: Clicking "Next" must validate only the inputs belonging to the active step.
  3. 3
    Step Navigation: Users must be able to step backward ("Previous") without triggering validation blocks.
1Step 1: Account Info ──[Next: Validates Step 1]──► Step 2: Company Details ──[Next: Validates Step 2]──► Step 3: Review & Submit
2 ▲ │
3 └──────────────────[Previous: No Validation]─────────┘

2. Implementing the Wizard with Dynamic Yup Schemas

1import React, { useState } from "react";
2import { Formik, Form, Field, ErrorMessage } from "formik";
3import * as Yup from "yup";
4 
5// Define individual schemas for each step
6const stepSchemas = [
7 // Step 1 Schema: Personal Details
8 Yup.object({
9 firstName: Yup.string().required("First name is required"),
10 lastName: Yup.string().required("Last name is required"),
11 email: Yup.string().email("Invalid email").required("Email is required"),
12 }),
13 // Step 2 Schema: Organization Details with conditional field
14 Yup.object({
15 companyName: Yup.string().required("Company name is required"),
16 hasTaxId: Yup.boolean(),
17 taxId: Yup.string().when("hasTaxId", {
18 is: true,
19 then: (schema) => schema.required("Tax ID is required when registered"),
20 otherwise: (schema) => schema.optional(),
21 }),
22 }),
23 // Step 3 Schema: Plan Selection
24 Yup.object({
25 planTier: Yup.string().oneOf(["starter", "growth", "enterprise"]).required("Select a tier"),
26 }),
27];
28 
29export function MultiStepOnboardingWizard() {
30 const [stepIndex, setStepIndex] = useState(0);
31 const isLastStep = stepIndex === stepSchemas.length - 1;
32 
33 const currentValidationSchema = stepSchemas[stepIndex];
34 
35 return (
36 <div className="max-w-xl mx-auto p-8 bg-slate-900 border border-slate-800 rounded-2xl text-white">
37 {/* Step Indicator */}
38 <div className="flex justify-between items-center mb-8 border-b border-slate-800 pb-4">
39 {["Identity", "Organization", "Subscription"].map((label, idx) => (
40 <div key={label} className="flex items-center gap-2">
41 <span
42 className={`h-7 w-7 rounded-full flex items-center justify-center text-xs font-bold ${
43 idx === stepIndex
44 ? "bg-cyan-500 text-slate-950"
45 : idx < stepIndex
46 ? "bg-emerald-500/20 text-emerald-400 border border-emerald-500"
47 : "bg-slate-800 text-slate-500"
48 }`}
49 >
50 {idx + 1}
51 </span>
52 <span className={`text-xs font-medium ${idx === stepIndex ? "text-cyan-400" : "text-slate-500"}`}>
53 {label}
54 </span>
55 </div>
56 ))}
57 </div>
58 
59 <Formik
60 initialValues={{
61 firstName: "",
62 lastName: "",
63 email: "",
64 companyName: "",
65 hasTaxId: false,
66 taxId: "",
67 planTier: "growth",
68 }}
69 validationSchema={currentValidationSchema}
70 onSubmit={async (values, { setSubmitting }) => {
71 if (!isLastStep) {
72 // Advance to next step; Formik preserves all existing values in memory!
73 setStepIndex((curr) => curr + 1);
74 setSubmitting(false);
75 } else {
76 // Final submission
77 console.log("Final Wizard Submission:", values);
78 await new Promise((r) => setTimeout(r, 1200));
79 setSubmitting(false);
80 alert("Account provisioned successfully!");
81 }
82 }}
83 >
84 {({ values, isSubmitting }) => (
85 <Form className="space-y-4">
86 {/* Step 1 Content */}
87 {stepIndex === 0 && (
88 <div className="space-y-4">
89 <div>
90 <label className="block text-xs text-slate-400 mb-1">First Name</label>
91 <Field name="firstName" className="w-full px-3 py-2 bg-slate-800 border border-slate-700 rounded text-sm text-white" />
92 <ErrorMessage name="firstName" component="div" className="text-xs text-rose-400 mt-1" />
93 </div>
94 <div>
95 <label className="block text-xs text-slate-400 mb-1">Last Name</label>
96 <Field name="lastName" className="w-full px-3 py-2 bg-slate-800 border border-slate-700 rounded text-sm text-white" />
97 <ErrorMessage name="lastName" component="div" className="text-xs text-rose-400 mt-1" />
98 </div>
99 <div>
100 <label className="block text-xs text-slate-400 mb-1">Email Address</label>
101 <Field name="email" type="email" className="w-full px-3 py-2 bg-slate-800 border border-slate-700 rounded text-sm text-white" />
102 <ErrorMessage name="email" component="div" className="text-xs text-rose-400 mt-1" />
103 </div>
104 </div>
105 )}
106 
107 {/* Step 2 Content */}
108 {stepIndex === 1 && (
109 <div className="space-y-4">
110 <div>
111 <label className="block text-xs text-slate-400 mb-1">Company Legal Name</label>
112 <Field name="companyName" className="w-full px-3 py-2 bg-slate-800 border border-slate-700 rounded text-sm text-white" />
113 <ErrorMessage name="companyName" component="div" className="text-xs text-rose-400 mt-1" />
114 </div>
115 
116 <div className="flex items-center gap-2 pt-2">
117 <Field type="checkbox" name="hasTaxId" id="hasTaxId" className="h-4 w-4 rounded bg-slate-800 border-slate-700" />
118 <label htmlFor="hasTaxId" className="text-xs text-slate-300">Company is tax registered (VAT/EIN)</label>
119 </div>
120 
121 {values.hasTaxId && (
122 <div>
123 <label className="block text-xs text-slate-400 mb-1">Tax ID / EIN</label>
124 <Field name="taxId" className="w-full px-3 py-2 bg-slate-800 border border-slate-700 rounded text-sm text-white" />
125 <ErrorMessage name="taxId" component="div" className="text-xs text-rose-400 mt-1" />
126 </div>
127 )}
128 </div>
129 )}
130 
131 {/* Step 3 Content */}
132 {stepIndex === 2 && (
133 <div className="space-y-4">
134 <label className="block text-xs text-slate-400">Choose Deployment Plan</label>
135 <div className="grid grid-cols-3 gap-3">
136 {["starter", "growth", "enterprise"].map((tier) => (
137 <label
138 key={tier}
139 className={`p-4 border rounded-xl cursor-pointer flex flex-col items-center capitalize text-sm font-semibold transition ${
140 values.planTier === tier
141 ? "border-cyan-500 bg-cyan-950/40 text-cyan-300"
142 : "border-slate-800 bg-slate-800/40 text-slate-400"
143 }`}
144 >
145 <Field type="radio" name="planTier" value={tier} className="sr-only" />
146 {tier}
147 </label>
148 ))}
149 </div>
150 </div>
151 )}
152 
153 {/* Navigation Buttons */}
154 <div className="flex justify-between pt-6 border-t border-slate-800 mt-6">
155 {stepIndex > 0 ? (
156 <button
157 type="button"
158 onClick={() => setStepIndex((curr) => curr - 1)}
159 className="px-4 py-2 bg-slate-800 hover:bg-slate-700 text-slate-300 text-sm font-semibold rounded-lg"
160 >
161 Previous
162 </button>
163 ) : (
164 <div />
165 )}
166 
167 <button
168 type="submit"
169 disabled={isSubmitting}
170 className="px-6 py-2 bg-cyan-600 hover:bg-cyan-500 text-white text-sm font-semibold rounded-lg disabled:opacity-50"
171 >
172 {isSubmitting ? "Processing..." : isLastStep ? "Complete Registration" : "Continue"}
173 </button>
174 </div>
175 </Form>
176 )}
177 </Formik>
178 </div>
179 );
180}

Interactive Quiz• Knowledge Check

Practice Quiz

Question 1
How does the multi-step wizard validate only the inputs on the active step?
Question 2
Why should the "Previous" step button be of type="button" rather than type="submit"?
Question 3
How do you achieve conditional validation in Yup (e.g. taxId required only if hasTaxId is true)?
Question 4
Where is the unified form data stored as the user navigates between steps?
Question 5
What is the purpose of step indicator badges in enterprise wizard design?
Next Lesson

Custom Form Controls with useField

Continue learning with hands-on practice, examples, and exercises in the upcoming topic.

Related Lessons

Previous LessonNext Lesson
Formik Architecture and Field ArraysCustom Form Controls with useField

Practice Quiz

Test your understanding of this lesson with 5 questions. Each question has one correct answer.

Mentor-Led Practical Training

Master React.js for Advanced with Hands-On Projects

Practice in live mentor-led sessions with real projects, mock tests, and verifiable certification at MSK Institute.

View Full CourseBook Free Demo
PreviousNext
PreviousPrevNext