- Fix Linux
arm64
binary name.
- Dependencies update.
- Add native Linux
arm64
support #116.
- Add native macOS
arm64
support #111.
- Add support for m1 through rosetta #106.
- Fix linux build #104.
- Fix multiple dependent fields #101.
- [ BREAKING ] Switch to
@rescript/react
. - [ BREAKING ] Update
bs-platform
.
- Add
metadata
.
- Fix Windows build.
- Fix stack overflow in large forms.
- Re-enable
dirty
function in interface.
- Make all List calls in PPX tail-recursive.
- Temporary disable
dirty
function in interface due to the BuckleScript issue.
- Make all fold calls in PPX tail-recursive.
- Fixed
submissionError
type bug.
[ BREAKING ] Formality
got a new API and is implemented as PPX now. Even though update shouldn't be hard for most of the cases, it's better to read through new docs as we introduced some new concepts and features. Old implementation is still around and available via FormalityCompat
interface.
bs-platform
updated tov7
.
- Add
*WithId
functors to support custom comparator in configs (details: #52).
- [ BREAKING ] React hooks support (
[email protected]
). - Add
FormalityCompat
to supportJSX@2
.
- [ BREAKING ]
bs-platform
updated to5.0.0
. - [ BREAKING ] Generalize payload of
FormStatus.SubmissionFailed
constructor (#49). - Add
dismissSubmissionError
. - Add
mapSubmissionError
. - Keep submission error on a screen (if any) while re-submitting.
- Reset validation state to
Pristine
on successful submission (#46 by @steinararnason)
- Add
dismissSubmissionResult
tosubmissionCallbacks
record. - (Chore) Update
bs-platform
.
- (Chore) Update
re-debouncer
.
Add form.reset()
function which resets the form to its initial state.
No changes.
- Add
form.dirty()
function which returnstrue
if any form field was touched,false
otherwise. - Add
form.valid()
function which returnstrue
if all form fields are valid,false
otherwise. Not available for forms w/ async validations. - Namespace async types. You might need to local open
Async
module for async validators in form config. E.g.
let validator = Async.{ field: Email, ... };
- Un-expose
React
module. I might accidentally broke some apps which have internalReact.re
module. Sorry!
- [ BREAKING ] Validation
result
type isBelt.Result.t(ok, message)
. Wheretype ok = | Valid | NoValue
.NoValue
tag should be used when optional field's value is empty.
There are a number of big changes in public API. Higher level changes are outlined below. Please, see updated documentation, inspect src/Formality.rei
and follow compiler warnings to update your forms. Also, see updated examples.
- [ BREAKING ] Fast-pipe & data-first style.
- [ BREAKING ]
value
type is removed from config. It 100% decouples forms from particular value type. - [ BREAKING ] Validation
result
type received new constructor:Optional
. It should be used when optional field's value is empty. You can safely remove confusingvalueEmpty
function from configs. Make sure that all validators of optional fields are updated. - [ BREAKING ] Validators are simply
list(validators)
now (instead ofMap
) and due tovalue
removal each validator receives single argument:state
. - Switch to
Belt
.
Formality.Dom.toValue*
&Formality.Dom.toChecked*
helpers are deprecated in favor of commonReasonReact
getters.
bs-platform
updated to4.0.6
.- Use
re-debouncer
.
bs-platform
updated to4.0.5
&reason-react
to0.5.3
. Thanks @jihchi!
- Added
Formality.Dom.toCheckedOnChange
&Formality.Dom.toCheckedOnBlur
helpers.
- Added
form.dismissSubmissionResult
to dismiss server errors without resetting the form. Under the hood, it changesFormStatus.Submitted
&FormStatus.SubmissionFailed
statuses toFormStatus.Editing
.
- Fixed emitting of invalid result when value is empty.
bs-platform
updated to3.0.0
. Thanks @jihchi!
- Fixed Map comparator. Thanks @jihchi!
- Fixed equality check in empty string helper. Thanks @rauanmayemir!
- Added interface file.
- Added docs.
- Form
status
is added.
type t('field, 'message) =
| Editing
| Submitting
| Submitted
| SubmissionFailed(list(('field, 'message)), option('message));
You can access this type via Formality.FormStatus
module.
Current status
is exposed via form
argument of the children
function. form.submitting
is kept for convenience.
- [ BREAKING ]
onSubmit
handler is changed.
Submission callbacks:
- type notifiers = {
- onSuccess: unit => unit,
- onFailure: unit => unit,
- };
+ type submissionCallbacks('field, 'state, 'message) = {
+ notifyOnSuccess: option('state) => unit,
+ notifyOnFailure: (list(('field, 'message)), option('message)) => unit,
+ reset: unit => unit,
+ };
onSubmit
prop:
- onSubmit=((state, {onSuccess, onFailure}) => ...)
+ onSubmit=((state, {notifyOnSuccess, notifyOnFailure, reset}) => ...)
Previously, if onSuccess
was called, form was reset. Now, each callback sets appropriate form status
, or you can explicitly reset
a form. Also with this change, you can store errors returned from a server in form status SubmissionFailed(list(('field, 'message)), option('message))
and render them in UI.
bs-platform
is updated to2.2.3
.
bs-platform@^2.2.2
is added topeerDependencies
.
- [ BREAKING ]
value
is user-defined type (wasstring
).
In form config:
+ type value = string;
+ let valueEmpty = value => value === "";
/* or */
+ let valueEmpty = Formality.emptyString;
- [ BREAKING ]
Formality.Dom.valueOnChange
replaced withFormality.Dom.toValueOnChange
andFormality.Dom.valueOnBlur
replaced withFormality.Dom.toValueOnBlur
to make DOM helpers more composable with non-stringvalue
. Also, subjectively, handlers are more transparent this way.
- onChange=(
- LoginForm.Email
- |> form.change
- |> Formality.Dom.valueOnChange
- )
+ onChange=(
+ event =>
+ event
+ |> Formality.Dom.toValueOnChange
+ |> form.change(LoginForm.Email)
+ )
- Fix regressions related to empty values validation on form submission
bs-platform
updated to2.2.2
.
- In case of optional field (e.g.
"" => Valid
) if value is empty string container will always emitNone
(instead ofSome(Valid)
).
- [ BREAKING ]
validationResult
type is set back to variant.meta
is removed.
- type validationResult('message) = {
- valid: bool,
- message: option('message),
- meta: option(string)
- };
+ type validationResult('message) =
+ | Valid
+ | Invalid('message);
Validate function looks like this:
validate: (value, _state) =>
switch value {
| "" => Invalid("Uh oh error"),
| _ => Valid
}
- [ BREAKING ]
exception ImpossibleResult
is removed as with the change above we don't get into impossible state anymore! 🎉🎉🎉
- Validation
result
type is renamed tovalidationResult
to avoid possible conflicts with Pervasive'sresult
.
- [ BREAKING ] Validation
result
type is simplified. Now it's just record.
- type result('message) =
- | Valid(bool)
- | ValidityBag(validityBag('message));
+ type result('message) = {
+ valid: bool,
+ message: option('message),
+ meta: option(string)
+ };
Validate function looks like this:
validate: (value, _state) =>
switch value {
| "" => {
valid: false,
message: Some("Uh oh error"),
meta: None
}
| _ => {
valid: true,
message: Some("Nice!"),
meta: None
}
}
Thanks @thangngoc89 for suggestion!
- [ BREAKING ] Global form
strategy
type is removed. Now strategy is defined via field validator. It meansstrategy
field is notoption
anymore.
- let strategy = Formality.Strategy.OnFirstSuccessOrFirstBlur;
- strategy: Some(Strategy.OnFirstSuccessOrFirstBlur)
+ strategy: Strategy.OnFirstSuccessOrFirstBlur
- strategy: None
+ strategy: Strategy.OnFirstSuccessOrFirstBlur
- [ BREAKING ] Signatures of
form.change
&form.blur
handlers are changed. Now both acceptvalue
instead of events. You can use exposed helpers to get value from event.
- onChange=(Form.Field |> form.change)
- onBlur=(Form.Field |> form.blur)
+ onChange=(Form.Field |> form.change |> Formality.Dom.valueOnChange)
+ onBlur=(Form.Field |> form.blur |> Formality.Dom.valueOnBlur)
- [ BREAKING ] Signature of
form.submit
handler is changed. Now it acceptsunit
instead of event. You can use exposed helper to prevent default.
- <form onSubmit=form.submit>
+ <form onSubmit=(form.submit |> Formality.Dom.preventDefault)>
- [ BREAKING ] Formality doesn't trigger
event.preventDefault
on form submission anymore. Handle it via exposed helperFormality.Dom.preventDefault
or however you like.
Thanks @grsabreu & @wokalski for suggestions!
Initial release.