Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to set or modify input values, instead of only set. #34

Merged
merged 5 commits into from
Oct 20, 2018

Conversation

thomashoneyman
Copy link
Owner

@thomashoneyman thomashoneyman commented Oct 20, 2018

What does this pull request do?

Formless currently allows users to set the value of a form field with the Modify query. This is a curiously-named query given that it is really a way to set a field, and there is no support for users who would like to apply a function to the form field instead.

This PR updates the library to distinguish between setting a field (field -> input -> field) or modifying it (field -> (input -> input) -> field). The Modify* family of queries all behave as true modifications now, with the previous setting behavior easily recovered using const. A new helper query, set, has been introduced to make this easy and be a drop-in replacement for how the modify query previously worked.

This also closes #32 by allowing you to force validation on a field that hasn't been touched yet -- simply do:

F.modifyValidate_ (SProxy :: SProxy "myField") identity

to set the field touched and run validation.

Additional Changes

In addition, this PR reworks the module structure of the library to achieve a few goals:

  • accurately reflect the purpose of various parts of the library as it has evolved (for example, Spec no longer has any relation to the concept of a "form spec" and has been renamed Types.Form)
  • make useful helper functions discoverable (for example, all helper queries were stuffed at the bottom of the component file before, making them difficult to discover through the noise. Now they have their own module)
  • Reduce the size of some files that were growing out of control (for example, the component file started to become quite large, mixing helper functions, types, and a large component along with lots of re-exports into a single module)

The new structure has no breaking changes for any user who previously did import Formless as F, as all modules are still re-exported. However, users who imported from multiple modules will need to update their code to the new module names.

Other Notes:

The project documentation will need to be updated to reflect the new set and modify capabilities of the library and the new locations of modules. The release notes for the 0.3.0 release must include a section describing what modules and functions have been moved so that users are able to migrate easily.

…ucture modules to more accurately reflect names and uses of functions and for clarity.
@thomashoneyman thomashoneyman added this to the 0.3.0 milestone Oct 20, 2018
@thomashoneyman thomashoneyman self-assigned this Oct 20, 2018
@@ -160,9 +160,9 @@ formlessField
. IsSymbol sym
=> ToText e
=> Newtype (form Record F.FormField) (Record fields)
=> Newtype (form Variant F.InputField) (Variant inputs)
=> Newtype (form Variant F.InputFunction) (Variant inputs)
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dariooddenino Helper classes that previously used the InputField variant will need to be updated to use the InputFunction variant instead, the only class on the component. The variant was changed to support InputFunction (input -> input) and modification.

@@ -72,7 +72,7 @@ renderEnabled state =
[ css "checkbox"
, HP.type_ InputCheckbox
, HP.checked $ F.getInput prx.enable state.form
, HE.onChange $ HE.input_ $ F.modify prx.enable (not $ F.getInput prx.enable state.form)
, HE.onChange $ HE.input_ $ F.modify prx.enable not
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These sorts of "toggle" functions are now possible in Formless @whoadave @crcornwell

ModifyValidateInput variant a -> do
st <- getState
let form = Internal.unsafeModifyInputVariant variant st.form
form' <- do
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has been updated to minimize state updates / re-renders by not calling out to the Modify or Validate queries

* Added helper queries for all public queries. Added SetAll and ModifyAll functions. Broke something...

* Fix instances

* Update examples. Rename replaceInputs to initialize to better reflect its purpose and function.

* Fix formatting

* Add wrapInputFunctions helper function. Add documentation to wrap* and unwrap* helpers.
@thomashoneyman thomashoneyman merged commit 73e4a89 into heterogeneous Oct 20, 2018
@thomashoneyman thomashoneyman deleted the modify-set branch October 20, 2018 18:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant