Build a Multistep Form in NextJs Using react-hook-form and ZOD

Поделиться
HTML-код
  • Опубликовано: 5 окт 2024

Комментарии • 119

  • @MiladJoodi
    @MiladJoodi 12 дней назад +1

    You really explain things easily. I believe that some people are born to be teachers.🙌✨

  • @BreadfortheSoul-lb3zr
    @BreadfortheSoul-lb3zr 5 месяцев назад +3

    Thank you for taking the time to share this. The Lord Jesus bless you.

    • @hamedbahram
      @hamedbahram  5 месяцев назад

      My pleasure! Glad it helped.

  • @raillyhugo3287
    @raillyhugo3287 7 месяцев назад +4

    Thank you, that's what exactly I was looking for. Concise and clear explanation! Keep up the good work!

  • @longsuabc
    @longsuabc 11 месяцев назад +1

    Really great and amazing video.
    Very clear explanations all the time. I am not a native English, but I can hear his English very clearly!!
    I respect you and your business!!!
    Cheers!!!
    From China! 💪💪✨✨👍👍👏👏

    • @hamedbahram
      @hamedbahram  11 месяцев назад

      Great to hear that! Welcome to the channel.

  • @almaducatel5830
    @almaducatel5830 4 месяца назад +1

    Thank you verry much for your time. You are a blessing.

  • @leonardorocchini9012
    @leonardorocchini9012 11 месяцев назад +6

    Nice video. that would be great to implement app routing in the multistep form so that we have a separate page for each step.

    • @hamedbahram
      @hamedbahram  11 месяцев назад +2

      For sure!

    • @raymondmichael4987
      @raymondmichael4987 3 месяца назад

      🤔🤔 actually that’s a good idea, I have several ways to leverage it “I guess “😊

  • @jeremiahchinwe1336
    @jeremiahchinwe1336 4 месяца назад +1

    This video has really helped me achieve my task

  • @irfansaeedkhan7242
    @irfansaeedkhan7242 3 месяца назад +4

    too much code in one component killed the main motive of react, it would have better to also show if each form is in different component because form could be bigger

    • @hamedbahram
      @hamedbahram  3 месяца назад +3

      This video is not so much about React component composition but more so about the concept of a multi-step form implemented using react-hook-form and zod for validation.

    • @raymondmichael4987
      @raymondmichael4987 3 месяца назад

      Using multiple forms for this lesson would have made the video too complicated for me.
      I think for delivering the intended concept, he chose the best approach.
      Once we understand the concept it’ll be much easier to na split the form into much smaller forms as we want and he mentioned it clearly 😊

    • @raymondmichael4987
      @raymondmichael4987 3 месяца назад

      @@hamedbahramthanks man, keep them coming ❤

  • @INetreba
    @INetreba 23 дня назад +1

    Thank you! I like your vibe

  • @ivandamyanov
    @ivandamyanov 7 месяцев назад +1

    Thanks for the great video. I really like react-hook-form but there seem to be very few videos about an important integration - custom inputs + react hook form. I read 3 different articles for different versions of the library and it is all implemented differently and some things don't work. Especially with a Typescript environment. I like that library but it proves to be very complicated for beginners to use it in a reusable way (custom components). Would be awesome if you could do a short video on that or redirect me to any good example you might know of for the latest version.

    • @hamedbahram
      @hamedbahram  7 месяцев назад

      Tell me more... are you using a UI library for your custom components?

  • @yogawithaaron
    @yogawithaaron 6 месяцев назад +1

    This video was tremendously helpful. Ty!

  • @sundayucheawaji6206
    @sundayucheawaji6206 4 месяца назад +1

    Thanks for this. It was really helpful.

  • @alir8zana635
    @alir8zana635 11 месяцев назад +1

    thank you so much for this video
    it really helped me implement it in my own project
    your videos are great and I hope you great success

    • @hamedbahram
      @hamedbahram  11 месяцев назад +1

      You're very welcome! I'm glad it helped, and I appreciate your comment!

  • @ammarhaidar5995
    @ammarhaidar5995 11 месяцев назад +1

    Awesome, just in time🎉🎉, appreciate your content, thanx.

  • @alexavery8182
    @alexavery8182 11 месяцев назад +1

    Hamed always delivers great content

  • @alextwin200e3
    @alextwin200e3 9 месяцев назад +1

    Thank you very much! It helped me a lot. Great content!

    • @hamedbahram
      @hamedbahram  9 месяцев назад

      You're welcome! Glad it helped!

  • @OutrospectiveOfficial
    @OutrospectiveOfficial 2 месяца назад +1

    Excellent content, thank you!

  • @htetlinlinnaing4994
    @htetlinlinnaing4994 3 месяца назад

    Thank you for your amazing Next.js content! If you have time, could you make a tutorial on adding/removing multiple fields dynamically on button click? It would be super helpful!

    • @hamedbahram
      @hamedbahram  3 месяца назад

      My pleasure! Do you mean adding conditional steps?

    • @htetlinlinnaing4994
      @htetlinlinnaing4994 3 месяца назад

      @@hamedbahram I meant a form where I can add or remove multiple fields dynamically, like adding or removing phone number fields on button click. Thank!

    • @raymondmichael4987
      @raymondmichael4987 3 месяца назад

      I think you mean handling fieldArray 😊.
      it’s a good one to learn from expert.

  • @kyle-andrewgovinder9902
    @kyle-andrewgovinder9902 11 месяцев назад +2

    Always providing us with amazing content, Hamed
    It's safe to say you taught me everything I know about Next

    • @hamedbahram
      @hamedbahram  11 месяцев назад

      Glad to hear that! I appreciate your comment.

  • @yasserhy
    @yasserhy 11 месяцев назад +2

    As always, brilliant video ❤

  • @imkir4n
    @imkir4n 11 месяцев назад +1

    Wow i was looking for the same🔥

  • @kristian970
    @kristian970 11 месяцев назад +1

    Great video! Thank you!

  • @siebe681
    @siebe681 11 месяцев назад

    This was something I was searching for! Thank you!

  • @hqasmei
    @hqasmei 11 месяцев назад

    Another great video, thanks Hamed!

    • @hamedbahram
      @hamedbahram  11 месяцев назад

      I appreciate it, Hosna! What is similar to how you implemented it?

  • @usamausman5225
    @usamausman5225 11 месяцев назад +1

    Please make a complete series on Next 14

    • @hamedbahram
      @hamedbahram  11 месяцев назад +1

      Everything is the same in NextJs 14, nothing has changed :) The only change is that server actions are now stable. But I'll make a video reviewing the release.

  • @SanderCokart
    @SanderCokart 11 месяцев назад +2

    We need a version that cam scale infinitely using lazy and pre loading but idk how you preload component 3 while component 2 is showing for example.

    • @hamedbahram
      @hamedbahram  11 месяцев назад +1

      Maybe have them as different components and lazy load the components and pass the promise to the form component. Just thinking out loud here...

  • @trusht
    @trusht 11 месяцев назад +2

    Thanks sir for the detailed explanation. I have tailwinds subscription so decided to apply this to my app. I am thinking to save input data to local storage just in case if the user navigates away with tons of information typed and when they come back to the form without frustration. What do you think?

    • @hamedbahram
      @hamedbahram  11 месяцев назад

      That's great idea Tacettin! I'd love for you to contribute to this project. Open a PR for the storage.

  • @tomasburian6550
    @tomasburian6550 2 месяца назад +1

    What always gives me hard time is trying to figure out some extra features that would fit into the process because as a pro I tend to get tasks that are easily out of the ordinary use case. For example, I want the user to input his company number on the first step and then not only validate that the input is not empty, but also that the number they provided is real and not made up.
    Is there a way to run a custom function for each step that would do something before it would let the user go on to the next step?

    • @hamedbahram
      @hamedbahram  2 месяца назад

      Yes you can have custom validation for each field.

  • @YasamanKarbasi
    @YasamanKarbasi 5 месяцев назад +1

    THANK UUU

  • @arezootony9715
    @arezootony9715 8 месяцев назад +1

    Amazing video. How do we disable the buttons in each step if the required fields are not filled ?

    • @hamedbahram
      @hamedbahram  8 месяцев назад

      Thank you! You can look at the `formState` returned from the `useFrom` hook.

    • @arezootony9715
      @arezootony9715 7 месяцев назад +1

      @@hamedbahram I tried isValid and isDirty but they do not work properly and I think the reason is they are matching with the whole Zod schema and not the items on the page.

    • @hamedbahram
      @hamedbahram  7 месяцев назад

      ​@@arezootony9715 seem like the solution would be to have separate forms for each step and hold the collected data in a global state.

    • @arezootony9715
      @arezootony9715 7 месяцев назад +1

      @@hamedbahram yes, that is exactly how I was doing with the forms I have. My only problem is keeping the form state when the user goes back to the previous form/step and see the form filled.

    • @hamedbahram
      @hamedbahram  7 месяцев назад

      @@arezootony9715 you need to lift the state of the form up to the parent or a global state.

  • @kyleroath
    @kyleroath 8 месяцев назад +2

    I know this weird, but I kept thinking like damn that chair looks comfy. Can anyone identify which chair that is?

    • @hamedbahram
      @hamedbahram  8 месяцев назад +1

      Haha 😅 Its from IKEA, the model name is Markus.

    • @kyleroath
      @kyleroath 8 месяцев назад +1

      @@hamedbahram ha thank you sir. sorry for the weirdness, thanks for the vid too!

    • @hamedbahram
      @hamedbahram  8 месяцев назад

      @@kyleroath no worries!

  • @leilamohamadpor3481
    @leilamohamadpor3481 11 месяцев назад +1

    خیلی عالی بود.این چیزی بود که من الان داشتم دنبال آن می گشتم
    من یک فرم با تعداد خیلی زیادی المنت دارم که باید مقادیر آنها را از کاربر دریافت کنم
    آیا به نظر شما لازم است که از state management ها استفاده کنم؟
    اگر راهنمایی ب فرمایید ممنون می شوم

    • @hamedbahram
      @hamedbahram  11 месяцев назад

      Khoshhaalam Leila Jan! Welcome to the channel 🙂

  • @imkir4n
    @imkir4n 10 месяцев назад +1

    12:05 hamed why the error is keep complaining even after user entered into the field?

    • @hamedbahram
      @hamedbahram  10 месяцев назад +1

      You can set the `mode` to `onChange` to update the error as the user corrects it.

    • @imkir4n
      @imkir4n 10 месяцев назад

      @@hamedbahram Thanks it worked. But Will this lead to multiple re-renders?

    • @hamedbahram
      @hamedbahram  10 месяцев назад

      @@imkir4n Yup it does. I don't know of any other way to watch the changes on the fields to wipe out the errors once we triggered the validation.

  • @dosamuel-mb
    @dosamuel-mb 4 месяца назад +1

    Hello, i added a button to submit the data to the API, but i can't even see my data in the console, i can't even log them and there is no error at all. Can someone help please ?

    • @hamedbahram
      @hamedbahram  4 месяца назад

      Clone my code and see what you're doing differently.

  • @davidfarah
    @davidfarah 10 месяцев назад +1

    Thanks

  • @saiguna6676
    @saiguna6676 3 месяца назад

    Thank you for the amazing video but if i have optional fields it's not working for that one how to solve it sir

    • @hamedbahram
      @hamedbahram  3 месяца назад

      What is an optional field, one that's not required you mean?

  • @AmitErandole
    @AmitErandole Месяц назад +1

    What if we need to show errors while the user is typing? Do we enable the onChange mode on react hook form?

    • @hamedbahram
      @hamedbahram  Месяц назад +1

      You can set the mode to onChange or separate the steps to individual forms.

    • @AmitErandole
      @AmitErandole Месяц назад +1

      @@hamedbahram ok will try that. Thank you for sharing your repos. They are quite helpful

  • @kennethlau8108
    @kennethlau8108 7 месяцев назад +1

    If we add a file upload input for example in step2 clicked next tp step3 and click back. It will have an error.

    • @hamedbahram
      @hamedbahram  7 месяцев назад +1

      Yeah this isn't a one-size-fits-all solution, you'd have to handle file inputs probably with separate forms for each step.

    • @kennethlau8108
      @kennethlau8108 7 месяцев назад +1

      @@hamedbahram any recommended ways to do so ?

    • @hamedbahram
      @hamedbahram  7 месяцев назад

      @@kennethlau8108 watch this → ruclips.net/video/CeAkxVwsyMU/видео.html

  • @dogcodes
    @dogcodes 6 месяцев назад +1

    Is there a way to remove the validation error message when the user inputs again after validation. So after the "is required" is shown then when I type again that message is not rendered

    • @hamedbahram
      @hamedbahram  6 месяцев назад +1

      You can pass `mode:"onchange"` or if you don't want to trigger state update on change, you can separate each step to an individual form and hold a global state for all the steps.

    • @dogcodes
      @dogcodes 6 месяцев назад

      @@hamedbahram Thank you!

  • @dhirajavasthi6539
    @dhirajavasthi6539 10 месяцев назад +1

    Hello @hamedbahram your content is very helpful can you please help me in below problam using zod and next js 13 or 14
    problem : How to read content of uploaded json file on react / next.js 13 or 14 using zod

    • @hamedbahram
      @hamedbahram  10 месяцев назад

      Not sure if I understand that. Zod is for validating or parsing an object, what do you mean by reading a json file?

  • @user-gm3lg8gp3m
    @user-gm3lg8gp3m 5 месяцев назад

    thank you

  • @abdulmalikzihad3542
    @abdulmalikzihad3542 9 месяцев назад +1

    Will the 2nd step submit the automatically?

    • @hamedbahram
      @hamedbahram  9 месяцев назад

      Yes if it passes the validation it submits the form.

  • @OmarDugha-o6l
    @OmarDugha-o6l 10 месяцев назад +1

    ❤❤❤

  • @juniorsemerzier660
    @juniorsemerzier660 11 месяцев назад +1

    how to remove the error message after the correction of the input value?

    • @hamedbahram
      @hamedbahram  11 месяцев назад

      You can pass mode: "onChange" to the `useForm` hook.

    • @codingwithlucy
      @codingwithlucy 10 месяцев назад +1

      @@hamedbahram I was just coming to ask the same question. What do you mean? Do you mean that on every form field you would use trigger on onChange?

    • @hamedbahram
      @hamedbahram  10 месяцев назад

      ​@@codingwithlucy What I meant is to pass the `mode` property to the `useForm` hook like so ↓
      ```
      const { register, trigger, ... } = useForm({
      ...
      mode: "onChange"
      ...
      })
      ```
      Does this answer your question?

    • @AravindK-tv5rh
      @AravindK-tv5rh 9 месяцев назад +1

      @@hamedbahram Isn't there any other way? like how it works normally in react hook form for a normal form...

    • @hamedbahram
      @hamedbahram  9 месяцев назад

      @@AravindK-tv5rh I'm not aware of any other way! Let me know if you could come up with something else from the docs.

  • @АнтонКобелев-з5ъ
    @АнтонКобелев-з5ъ 11 месяцев назад +1

    Do you have this code on git hub?

    • @hamedbahram
      @hamedbahram  11 месяцев назад

      Yes the link is in the video description.

  • @dolapojohnsonn
    @dolapojohnsonn 6 месяцев назад

    Nice content. But can I get access to the github repo please?

    • @hamedbahram
      @hamedbahram  6 месяцев назад +1

      Link to repo is in the video description.

    • @dolapojohnsonn
      @dolapojohnsonn 6 месяцев назад

      @@hamedbahram Thank you, I'm grateful

  • @navjotsingh2457
    @navjotsingh2457 8 месяцев назад

    tysm

  • @mathuraditya7
    @mathuraditya7 11 месяцев назад +1

    Hey, have you tried @rafty/ui for UI?