Extract and set form values through the DOM—no frameworks required! https://github.com/TheoryOfNekomata/formxtra
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

00-rationale.md 2.6 KiB

123456789101112131415161718192021222324252627282930313233343536373839
  1. # Rationale
  2. **Why the need for another form library?**
  3. Let us set some facts about existing form libraries:
  4. * Form libraries, especially framework-specific ones have verbose syntax.
  5. * Please go to your form library of choice and compare the syntax yourself.
  6. * Form libraries are dependent on the architecture of the framework (such as [React Hook Form](https://www.npmjs.com/package/react-hook-form) and [Formik](https://www.npmjs.com/package/formik)) and
  7. requires using their features.
  8. * Form libraries have differing ways on how to manage state, usually piggybacking on the data flow of the framework they
  9. are dependent on.
  10. * Form libraries are relatively complex to what they are supposed to be doing such as providing wrappers to custom
  11. components, in which compatibility should be in the hands of the component author.
  12. **What does `formxtra` offer?**
  13. * `formxtra` aims to simplify the syntax to just invoking two functions - `getFormValues()` and `setFormValues()`.
  14. * `formxtra` is not dependent to any library and is highly interoperable.
  15. * `formxtra` is dependent only to the DOM. Since accessing the DOM is fully synchronous, the same can be said for the
  16. entire operation of `formxtra`.
  17. * There are no other paradigms introduced by `formxtra`. For the library to do its intentions, it only requires
  18. respecting the HTML DOM spec, such as providing names to inputs and binding them correctly to forms, which is what
  19. all (data-driven) websites should do anyway.
  20. * `formxtra` is lightweight, even smaller than [React Hook Form](https://www.npmjs.com/package/react-hook-form) and [Formik](https://www.npmjs.com/package/formik).
  21. * `formxtra` is already type-safe, being written in TypeScript and providing types, thanks to [pridepack](https://www.npmjs.com/package/pridepack) as a scaffold.
  22. **What does `formxtra` not offer?**
  23. * `formxtra` is not a validation library, nor does it provide utility functions for validation.
  24. * However, one could use `formxtra` in tandem with other validation libraries
  25. such as `ajv` or `yup` for instance, by validating the values returned by `getFormValues()`.
  26. * `formxtra` does not provide compatibility to custom components.
  27. * Because custom components have different
  28. implementations that mostly favor user experience over compliance, `formxtra` does not guarantee it can work with them
  29. out of the box.
  30. * However, the solution for this is to provide a corresponding `<input type="hidden">` element for each custom\
  31. component, which should always get the latter's serializable value. In return, this can also simplify the submission
  32. of the form as the custom components' values are already in the form.