Forms with validation (Next.js + Zod + react-hook-form)

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

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

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

    Thanks a lot man. God bless you

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

    i have two date values From and To, i want to validate those dates, such the To date value is not earlier than the From date, how to do so??

  • @MrPukamir
    @MrPukamir Год назад

    what if your select options would come from db, how your code would change?

    • @ramozdev
      @ramozdev  Год назад

      This only affects the zod schema. You can treat the select the same as the name in this example. Define the zod schema validation for the select to expect a non-empty string. By doing this you are accepting any string value from the select, expect for empty strings.

  • @techs7296
    @techs7296 Год назад

    Why form has weight as string defined, makes it difficult to post the data into the database.

    • @ramozdev
      @ramozdev  Год назад

      I do this because there is no way to return a JavaScript number from an input element. Please note, on 2:12 I explained that all inputs return a string in HTML, even the number input. You can verify this by checking the type of `event.target.value` when trying to read a value from an input.

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

      @@ramozdev I asked because I really want a proper solution. For now working by Using Number() .Open to any solution .

    • @filipfedorisin3457
      @filipfedorisin3457 Год назад

      @@techs7296 you can link everything to state object with onchange sync and then on submit verify the data, then you can get anything and bypass the string parsing... optimally regex, then you can completely remove zod and react hook form