Form

  • Published on
    In this article, I will show you how to handle form errors using React, Zod, Formik. You will learn how to create a form that supports both create and edit operations, how to fetch data for dynamic parts of the form with loading and error handling, how to validate the form using Zod, how to mock server errors using MSW, how to use Formik to manage the form state and submission. The form will also have features such as disabling during submission, displaying field errors, validating initial values when editing, and validating submit input when submitting. I will also cover some of the edge cases and best practices for form error handling with unit tests.
  • Published on
    Learn how to reset forms to their initial state in React, whether you are working with controlled or uncontrolled inputs. This comprehensive guide provides step-by-step instructions for implementing form resets, ensuring a seamless user experience. Gain insights into managing form resets in React and choose the approach that suits your project`s needs.
  • Published on
    Lazy loaded options allow users to search and select options from a list without the need to load all the options at once. This can be especially useful for forms with a large number of options or for options that are constantly changing. In this post, we will cover the simples approach for implementing async options in your forms, including using AJAX requests and APIs. We will simplify from previous blog post and add initialValues to make it possible to use this form, as an edit form.
  • Published on
    Let`s assume a situation like this. You are a moderator on a social media app. You got the report that users with the nickname "Legend27" and "Bob123" do not behave well in the comment section. You just collected all suspicious comments, but the manager told you that "Legend27" is specially treated and can not get account suspension. To handle this situation you should unselect the "Legend27" value from the "users" input, and the application should clean up only values related to the unselected user, but the rest of the comments leave without modification.
  • Published on
    Periodically few inputs are related to each other, and options values inside depend on the previous option from another select input. We could define all possible outcomes and filter out records, but this could be inefficient. Another issue is that we could not add/remove options till the new production update. To resolve this issue we can send a request for options values for the specific select input.
  • Published on
    Forms are primary components available almost on any website. We are using them to collect information from users. Starting from a simple contact form to a complex multistep order form. Managing multistep forms can be cumbersome, especially when we add custom validation.