V6 - React Hook Form - building dynamic form (Field Array)

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

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

  • @bencodes
    @bencodes 3 года назад +10

    You sir, are an amazing human for making forms so easy!

  • @mvssss_
    @mvssss_ 2 года назад +1

    Thank you very much for this video!

    • @bluebill1049
      @bluebill1049  2 года назад +1

      Thanks, this is an old version, maybe it's worth checking v7 instead.

  • @JojoNicho
    @JojoNicho 4 года назад +2

    Thanks for the great video! I can already see real-life scenarios where this feature would be handy. Also noticed your improved English. Keep it up, I'm a fan!

  • @BezalelTheCraftsman
    @BezalelTheCraftsman Год назад +1

    Thanks man! Good stuff 👍

    • @bluebill1049
      @bluebill1049  Год назад +1

      Please checkout the new version v7, v6 is 2 years behind.

  • @chaddpoggenpoel6727
    @chaddpoggenpoel6727 4 года назад +1

    Amazing video. Super valuable information. Will definitely play with it and ask in comments if I have a question. Not sure if I will have any though. Explanation was on point and concise! Keep up the good work! Thank you and God bless you !

  • @DeepakKapiswe
    @DeepakKapiswe 4 года назад +1

    Great and helpful Video, Thanks for sharing

  • @RahdixCloudNine
    @RahdixCloudNine 2 года назад +1

    subscribed and many thanks Bill, amazing!

  • @billzhou8686
    @billzhou8686 3 года назад +1

    So Coooo...ooool. Love 👍

  • @rohithsrivathsav6110
    @rohithsrivathsav6110 4 года назад +1

    Awesome explanation, subscribed!

  • @danielperez3559
    @danielperez3559 3 года назад

    Gracias!

  • @asimhafeezz
    @asimhafeezz 4 года назад +1

    it’s awesome, thanku ❤️.

  • @aimanjaffer
    @aimanjaffer 3 года назад +1

    What's the use of while using useFieldArray forms

  • @tbass.p3480
    @tbass.p3480 3 года назад +1

    you are a life saver, thank you! Me and my dificulty to understand documentations ahhhh... now my problem changed: "how can i made a update form with it? populating a list with a json and allow the user to edit it anyway?"

  • @ravendonly1
    @ravendonly1 4 года назад +1

    THANK YOU SO MUCH!

    • @bluebill1049
      @bluebill1049  4 года назад

      YOU ARE WELCOME! ❤️

    • @ravendonly1
      @ravendonly1 4 года назад

      @@bluebill1049 how can i apply nested default value in second append

    • @ravendonly1
      @ravendonly1 4 года назад

      codesandbox.io/s/react-hook-form-usefieldarray-nested-arrays-x7btr?file=/src/nestedFieldArray.js

    • @bluebill1049
      @bluebill1049  4 года назад

      @@ravendonly1 you can use append at the nested child with at useEffect, or you can use setValue('test', []) to update the entire field array.

  • @Ady567
    @Ady567 4 года назад +1

    Thanks for the demo video. I am stuck with nested dynamic form (Same as your form but with one more append for specific field), please suggest something for this.

    • @bluebill1049
      @bluebill1049  4 года назад +1

      take a look at the example folder, there is an example of array of array

  • @Evkayne
    @Evkayne 4 года назад +1

    amazing

  • @zhalux19
    @zhalux19 3 года назад +1

    Can you add yup schema validation to this? Noticed the array abject shape validation did not work for version react hook form version 6

  • @danielpreza4159
    @danielpreza4159 3 года назад +1

    thank you for the video but I have a question, how can I show by default elements?

    • @bluebill1049
      @bluebill1049  3 года назад +1

      use `defaultValues` at useForm, or you can also use `reset` API at `useEffect`.

    • @danielpreza4159
      @danielpreza4159 3 года назад +1

      @@bluebill1049 can you give me an example using defaultValues at useForm please
      because my input name is like this: name={`checker[${ index }].name`}

  • @joe-sydney-au
    @joe-sydney-au 2 года назад +1

    Has the API for react-hook-form v.7 changed with respect to refs ? I get errors on the line ref={register()} inside input, what's going on?

  • @ramonmaciel6230
    @ramonmaciel6230 4 года назад +1

    Amazing video, amazing lib! A little doubt, how I render a input components before run the append?

    • @bluebill1049
      @bluebill1049  4 года назад +1

      what's the reason to re-render your input?

    • @ramonmaciel6230
      @ramonmaciel6230 4 года назад +1

      @@bluebill1049 Hi! This isn't a re-render, I guess. I just need to have an input before clicking on append button. I don't know if was clear 😅

    • @bluebill1049
      @bluebill1049  4 года назад +1

      @@ramonmaciel6230 check the doc for `defaultValues`, there is an example in the doc as well.

  • @sergio201083
    @sergio201083 4 года назад

    Hi Bill, could you prepare a demo showing how to bind the data from the Redux storage with useFieldArray? I'm having some problems with it. Thank you. Great Video and Thank you for you helping.

  • @guillaumek8029
    @guillaumek8029 3 года назад +2

    Thank you !
    Im not sure the 'remove' methods provided by the lib is really removing at specified index tho. For me ths this doesn't work at all, it just remove the last of the array ..
    EDIT: I'm a noob. Please do not use as the key the index of the map when you iterate over you inputs. There is an 'id' property auto generated in your item that you must use as the key. At least, it's how i got it working

    • @bluebill1049
      @bluebill1049  3 года назад +1

      Have a play this one: codesandbox.io/s/react-hook-form-usefieldarray-vy8fv

    • @guillaumek8029
      @guillaumek8029 3 года назад

      @@bluebill1049 I saw you respond to everyone on every forums... and now even on a YT channel, now that's dedication ! Thank you so much :)

    • @bluebill1049
      @bluebill1049  3 года назад

      It's a passion to make something work for us (developers).

    • @jackhoang5019
      @jackhoang5019 3 года назад +2

      @@bluebill1049 you know what? I subscribed your channel after reading this one "It's a passion to make something work for us (developers)."

    • @bluebill1049
      @bluebill1049  3 года назад

      @@jackhoang5019 Thanks, Jack.

  • @abelmurua6980
    @abelmurua6980 2 года назад

    Great video, thanks. I have a typescript error. When I enter 'name' as the parameter for useFieldArray({}) I get this typescript error: ******** "Type 'string' is not assignable to type 'never'. The expected type comes from property 'name' which is declared here on type 'UseFieldArrayProps'" ******** any idea why? When I remove my type of from useForm(); this error disappears

  • @turin1100
    @turin1100 2 года назад

    How can i set empty object into fields array on init?

  • @Max-xp3tf
    @Max-xp3tf 3 года назад

    Hello thank you for this awesome video. I really love the library . I just have a question if someone can help me. I'm using the version 7 at the moment but I think the logic pretty much the same. There is my question:
    Is it okay to leave the append function with an empty object: append({})
    ..or should I always give the default values inside of it?
    I suppose that if I don't, it wil just pick the defaultValues from each individual inputs? I'm a little bit confused because in the doc, the examples always specifies them in the append fuction, even if there is also defaultValues present in each input.

  • @josephcoyle8126
    @josephcoyle8126 2 года назад

    This may just apply to V7, but I found that instead of just doing {...register()}, I had to do {...register("name")} to see any values in my onSubmit array.

  • @entertainmentstack2518
    @entertainmentstack2518 3 года назад

    Hi, I have a doubt, If the default values has a object data
    For eg: defaultValues: {
    "recipeTags": {
    "mainIngredient": ["Rice"],
    "course": ["All-day"],
    "cuisine": ["Chinese"]
    }
    }
    Now I want to loop :"recipeTags" using UseFieldArray. Is it possible?

    • @bluebill1049
      @bluebill1049  3 года назад

      it's possible but, recipeTags should be an array as well.

  • @rujalsapkota3824
    @rujalsapkota3824 4 года назад +1

    Could you please tell me how to set defaultValues through condition ??
    defaultValue={editMode ? 'Hi':' '}
    its not working

  • @bpark765
    @bpark765 4 года назад +1

    Hey Bill, is it possible to use the hook multiple times in a form?

    • @bluebill1049
      @bluebill1049  4 года назад

      YES :)

    • @bpark765
      @bpark765 4 года назад

      @@bluebill1049 do you mean by separating form fields into their own components and calling the hook in each of them? or is there a way to call the hook multiple times within 1 component?

    • @bluebill1049
      @bluebill1049  4 года назад +1

      @@bpark765 take a look at this example: codesandbox.io/s/react-hook-form-usefieldarray-nested-arrays-x7btr

    • @bpark765
      @bpark765 4 года назад +1

      @@bluebill1049 Exactly what I was looking for! You're the best 👍

  • @mahendranath2504
    @mahendranath2504 3 года назад +1

    Thank you so much very helpful, can you increase the voice, it very low, and can you zoom your screen bigger, it a very small letter, pls

    • @bluebill1049
      @bluebill1049  3 года назад +1

      sorry about that, I will make sure to improve that next time. I am not a professional RUclipsr, but i am learning my way through. Thanks

  • @rujalsapkota3824
    @rujalsapkota3824 4 года назад +1

    How to add error.message for each field ???? I am unable to use optional chaining

    • @bluebill1049
      @bluebill1049  4 года назад +1

      errors.test && errors.test.message (if you can't use optional chaining)

    • @rujalsapkota3824
      @rujalsapkota3824 4 года назад +1

      ​@@bluebill1049 thanks

  • @wolixe
    @wolixe 3 года назад

    What if I want to store the content directly in an array instead of in Objects.
    "names" : [
    "John",
    "Steve
    ]

  • @JesseQuickEats
    @JesseQuickEats 3 года назад +1

    Can you show us how to handle nested data? ex: instead if "name":"Hello" How can we make change to "Name": { "firstName": "Hello", "lastName": "World"}, "Type":"test" etc...

    • @bluebill1049
      @bluebill1049  3 года назад +1

      name="yourDetails.firstName"

    • @JesseQuickEats
      @JesseQuickEats 3 года назад

      @@bluebill1049 Hello Bill, Can you give a quick example on Nested arrays Ex: "Name": [{ "firstName": "Hello", "lastName": "World"}], "Type:"newTest". is there a video I can follow for this
      ?

    • @bluebill1049
      @bluebill1049  3 года назад

      @@JesseQuickEats take a look at the hook form repo, there is an example in the examples folder.

  • @chaitanyasagar7432
    @chaitanyasagar7432 2 года назад

    On click how to reset only one form in the fields array and leave the
    rest as it is…

    • @bluebill1049
      @bluebill1049  2 года назад

      reset({
      ...getValues(),
      newDate: 'test'
      })

  • @sheikhmuhammedshoaib1124
    @sheikhmuhammedshoaib1124 3 года назад +1

    How to populate arrayfield with data

  • @MrFawads
    @MrFawads 3 года назад

    Please use an external microphone.

  • @MW-fc4ge
    @MW-fc4ge 3 года назад

    funny how much the battery percentage bothers me

  • @berlino5563
    @berlino5563 4 года назад

    Poor quality video, it is a problem, i can’t read

    • @bluebill1049
      @bluebill1049  4 года назад +1

      It's still processing for HD.

    • @bluebill1049
      @bluebill1049  4 года назад +2

      It's 4K, that's why taking a while to process.