voliva / formicary Goto Github PK
View Code? Open in Web Editor NEWLicense: MIT License
License: MIT License
I'm currently working on a major release 0.3.0. Branch is in https://github.com/voliva/formicary/tree/v3.
I published the first preview to npm as 0.3.0-beta.0
. Please note the API is still subject to change before finishing, so use it at your own risk.
What this release addresses mainly is:
FormicaryContext.Provider
to avoid prop-drilling if desiredformRef
parameter omitted. If it's omitted, it will grab the formRef from the context instead.createKeyFn<FormModel>()
that will give a function that should autocomplete the paths for FormModel
, plus providing the correct type for each parameter.useErrors
will now return a type-safe dictionary of elements when using the paths overload (e.g. useErrors(form, 'name', 'age')
returns type { name: Error, age: Error }
).useControl
and useControlStateless
now don't require an initial value: The value will be undefined
by default.undefined
to reset them as empty.undefined
for type safety, except getFormValue
to make matters simple. Be aware some values could be undefined
, although it should not happen if validation rules are set up and form is marked as valid.useFieldChanges(key, cb: (value, isInitial) => void)
that will call the call-back every time that the field changes its value (it will also call it with the initial value setting isInitial
to true)getInitialValue
and getFormInitialValue
to get the initial value of a field or the form respectively.getAllErrors
to get a map with the fields that fail validation.isRequired()
isAtLeast(5)
)setValidatorMessages
or through an optional parameter when creating it.true
(value is valid) or a list of error messages.FormRef<FormModel>
is assignable to another variable with a subtype. This is particularly useful for subcomponents that only take a few properties of the whole model.useInput
useInput
now requires the key. It will ignore the name
attribute of the element it gets attached to.useErrors
, etc.).
useError(form, ['name', 'age'])
should become useErrors(form, 'name', 'age')
.useError(form, v => [v.name, v.age]))
is alright, but won't have the new enhanced type safety.isRequired
, isNumber
and isInteger
must now be called to get the actual validator.isRequired
will now return the value is valid if the value is nil, otherwise it would not be possible to make e.g. an optional numeric field. To migrate, they can be composed with pipeValidators(isRequired(), {{validator}})
.false
now when the value is invalid. On that case they must return a list of errors messages.useWatch
renamed to useFieldValue
- Reason: it's more descriptive of what it's returning.useFormChanges
renamed to useFormValue
- Reason: it's more descriptive of what it's returning.useControlSubscription
renamed to useControlStateless
- Reason: the name was misleading, it's not creating a Subscription, but returning something that you can subscribe to without using a state.readField
renamed to getFieldValue
- Reason: More descriptive and consistent with the setFieldValue
counterpart.readForm
renamed to getFormValue
- Reason: More descriptive and consistent with the setFormValue
counterpart.FormRef
is now opaque. It can still be used to pass the formRef around, but its properties are private and can't be accessed. Use exported methods instead.(Release open to feedback)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.