Skip to content

v3.7.0

Compare
Choose a tag to compare
@akuzko akuzko released this 21 Feb 20:47
· 13 commits to master since this release

New Features

  • Added validation rule wildcard index captures for validating collection items. A rule named items.(index).value follows the same validation logic as items.*.value, but also will pass index property with corresponding collection index to validator function (see example bellow). This is especially handy when item's validation depends on other items in the collection.
  • Added pinned validation dependencies. A validation like items.*.max with dependency like items.*.min would mean that change of any "min" input in the collection will re-validate every "max" input. To avoid this behavior, dependency items.^.min may be used now. This means that if, for instance, items.1.min input changes, and the form is in "validate-on-change" state, only items.1.max input will be re-validated. For example:
function ItemsForm() {
  const { $ } = useForm({
    validations:  {
      'items.*.min': 'presence',
      'items.(index).max': {
        rules: [
          'presence',
          (value, { index, attrs }) => {
            if (value <= attrs.items[index].min) {
              return 'Has to be greater than "min";
            }
          }
        ],
        deps: ['items.^.min']
      }
    }
  });
  // ...
}

Other Improvements

  • helpers config option can now accept an array of helpers-generating functions for convenience.

Fixes

  • Fixed a bug when validation of items.1.something validation rule would also trigger items.*.something rule validation for items.1.something input, which causes a problem when collection items has none or one element, and thus validations of items.*.something rule should not reach non-existing input.