Releases: akuzko/re-use-form
Releases · akuzko/re-use-form
v2.7.0
Release Description
- Added support for a
config
prop to generated dedicated form'sFormProvider
component. This config is merged into the one defined bymakeForm
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 andisValid
flag to helper object returned byuseForm
hook. - Added linter coverage to example forms, fixed revealed issues, improved example forms functionality.
v2.6.0
v2.5.0
Release Description
-
Added validation dependencies by declaring validation as an object with
rules
anddeps
properties, whererules
specify any acceptable validation rules, anddeps
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
Release Description
- When calling input validator, form will pass it's attributes as
attrs
option and name of the input being validated asname
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
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 tosetErrors
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, likeonBlur
events without affecting the rest of the form. - Fixed some README issues
[email protected]
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 underdeps
config property - Fixed number of mistakes in README. It was also updated according to package renaming.
v2.1.0
v2.0.0
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.