Skip to content

Commit

Permalink
Add reset form state helper. Closes #41 (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
medson10 authored and fakenickels committed Mar 19, 2018
1 parent e0fe046 commit ed63ed1
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions re/ReForm.re
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ module Create = (Config: Config) => {
| HandleFieldValidation((Config.fields, value))
| HandleError(option(string))
| HandleChange((Config.fields, value))
| HandleSubmit;
| HandleSubmit
| ResetFormState;
type values = Config.state;
type schema = list((Config.fields, Validation.validation(values)));
module Field = {
Expand Down Expand Up @@ -65,7 +66,8 @@ module Create = (Config: Config) => {
type onSubmit = {
values,
setSubmitting: (bool) => unit,
setError: (option(string)) => unit
setError: (option(string)) => unit,
resetFormState: unit => unit
};

type state = {
Expand Down Expand Up @@ -104,6 +106,7 @@ module Create = (Config: Config) => {
},
reducer: (action, state) =>
switch action {
| ResetFormState => ReasonReact.UpdateWithSideEffects({...state, values: initialState, errors: [], isSubmitting: false}, (self => onFormStateChange(self.state)))
| HandleSubmitting(isSubmitting) =>
ReasonReact.UpdateWithSideEffects(
{...state, isSubmitting},
Expand Down Expand Up @@ -155,6 +158,7 @@ module Create = (Config: Config) => {
(
self => {
onSubmit({
resetFormState: () => self.send(ResetFormState),
values: state.values,
setSubmitting:
isSubmitting => self.send(HandleSubmitting(isSubmitting)),
Expand Down

0 comments on commit ed63ed1

Please sign in to comment.