Skip to content

Releases: akuzko/re-use-form

v2.7.0

17 Feb 20:21
Compare
Choose a tag to compare

Release Description

  • Added support for a config prop to generated dedicated form's FormProvider component. This config is merged into the one defined by makeForm function and can be used to declare/pass values that depend on component context (i.e. values obtained from other hooks, etc).
  • Exposed dropError helper function and isValid flag to helper object returned by useForm hook.
  • Added linter coverage to example forms, fixed revealed issues, improved example forms functionality.

v2.6.0

16 Feb 10:03
Compare
Choose a tag to compare

Release Description

  • Added makeForm helper function that can be used to declare dedicated forms with easy-to-use hooks.
  • Exposed attrs as one of the props returned by both useForm and usePartialForm hooks.

v2.5.0

12 Oct 08:12
Compare
Choose a tag to compare

Release Description

  • Added validation dependencies by declaring validation as an object with rules and deps properties, where rules specify any acceptable validation rules, and deps is an array of dependency input names. For example:

    function ItemForm() {
      const {$} = useForm({}, {
        min: ["presence", "numericality"],
        max: {
          rules: [
            "presence",
            "numericality",
            function(value, {attrs}) {
              if (value <= attrs.min) {
                return "Should be greated than 'min'";
              }
            }
          ],
          deps: ["min"]
        }
      })
    }

    Wildcards are also supported as dependencies (more details in README)

  • Initial config resolution is now memoized to get rid of redundant resolutions on each render.

v2.4.0

10 Oct 20:18
Compare
Choose a tag to compare

Release Description

  • When calling input validator, form will pass it's attributes as attrs option and name of the input being validated as name option by default. This allows to declare custom wildcard validations that depend on other form attributes. For example:
const {$, withValidation} = useForm({name: "", items: []}, {
  "name": "presence",
  "items.*.start": "presence",
  "items.*.end": ["presence", function(value, {name, attrs}) {
    const index = name.split(".")[1];

    if (+value < +attrs.items[index].start) {
      return "Should be greater than 'Start'";
    }
  }]
});
// ...

v2.3.0

22 Sep 21:38
Compare
Choose a tag to compare

Release Description

  • Updated setErrors function to accept only plain object of errors, and throw this object otherwise. When used in promises, pattern like .catch(setErrors) may result in arbitrary error being passed to setErrors function, resulting in assigning this error's constructor name string as "name" input's error message, which not only very confusing, but also swallows exception meant to be thrown.
  • Updated validate function to allow to validate a single input by passing it's name to function. Can be used for validating stand alone inputs at any custom behavior, like onBlur events without affecting the rest of the form.
  • Fixed some README issues

[email protected]

21 Sep 20:14
Compare
Choose a tag to compare

Release Description

  • Project has been renamed to re-use-form as more usable name.
  • Improved dynamic config API: instead of useMemo flags and custom hooks, one can now simply provide config dependencies under deps config property
  • Fixed number of mistakes in README. It was also updated according to package renaming.

v2.1.0

22 Aug 21:37
Compare
Choose a tag to compare

Release Description

  • Added usePartial helper hook that can be used to extract parts of main form business logic into dedicated partial/nested form components
  • Updated and improved README

v2.0.0

08 Aug 20:48
Compare
Choose a tag to compare

Release Description

  • useForm hook has been re-implemented from scratch for much more performant, clean and maintainable API. The most important changes involve validation definitions and other hook configuration options. Basically, updated README describes the new way of working with the hook.