-
-
Notifications
You must be signed in to change notification settings - Fork 32
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
Conversation
…ucture modules to more accurately reflect names and uses of functions and for clarity.
@@ -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) |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
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
). TheModify*
family of queries all behave as true modifications now, with the previous setting behavior easily recovered usingconst
. A new helper query,set
, has been introduced to make this easy and be a drop-in replacement for how themodify
query previously worked.This also closes #32 by allowing you to force validation on a field that hasn't been touched yet -- simply do:
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:
Spec
no longer has any relation to the concept of a "form spec" and has been renamedTypes.Form
)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
andmodify
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.