Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upSupport field-level validation with variants #14
Conversation
thomashoneyman
added some commits
Jul 31, 2018
This comment has been minimized.
This comment has been minimized.
|
This should be an unreachable case, existing only so that validators have access to the full form state when they run. The user is still obligated to provide validators -- they're, at the moment, not optional. Though perhaps they could omit validators so long as the input and output types are the same. |
This comment has been minimized.
This comment has been minimized.
|
At this point I've essentially converged on the newtype Validation m e a b = a -> m (V e b)except I'm relying on |
thomashoneyman
added some commits
Aug 6, 2018
thomashoneyman
added some commits
Aug 7, 2018
thomashoneyman
added this to the 0.2.0 milestone
Aug 7, 2018
thomashoneyman
self-assigned this
Aug 7, 2018
thomashoneyman
added some commits
Aug 10, 2018
This comment has been minimized.
This comment has been minimized.
|
Currently still a bug: the validators have access to global state at form initialization, but then continue to reference that first original value forever afterward. Need to be updated to pull new state on each run. |
thomashoneyman
added some commits
Aug 11, 2018
This comment has been minimized.
This comment has been minimized.
thomashoneyman
added
the
help wanted
label
Aug 11, 2018
This comment has been minimized.
This comment has been minimized.
thomashoneyman
added some commits
Aug 11, 2018
thomashoneyman
reviewed
Aug 11, 2018
| [ HP.value $ F.getInput prx.secretKey1 st.form | ||
| , HE.onValueInput $ HE.input \str -> F.AndThen | ||
| (F.modifyValidate_ prx.secretKey1 str) | ||
| (F.validate_ prx.secretKey2) |
This comment has been minimized.
This comment has been minimized.
thomashoneyman
Aug 11, 2018
Owner
This is an example of how you can make sure dependent fields are also validated.

thomashoneyman commentedAug 7, 2018
What does this pull request do?
This PR introduces a fix for #11. Validation was previously done by providing a
form InputField -> m (form InputField)function, which would run any time theValidatequery was triggered. In effect, each field's validation was bundled up into one validation function that ran on all fields any time validation was triggered on any individual field. Perhaps not the worst issue in the world -- unless validation on a field was expensive or had side-effects. Imagine a single key press in an unrelated text field triggering several server calls!This PR changes the
ModifyandValidatequeries to instead take a variant. The variant notes which field is meant to be updated or validated and only runs the relevant function on that field. There is still aValidateAllfunction that makes it possible to run all validators.Finally, it ensures that you can still perform these types of validation:
i -> m (Either e o))How should this be manually tested?
Verify that the examples still behave as expected.
Other Notes:
This PR is a work in progress. There is still a bit more to do:
pure <<< F.unwrapRecord <<< unwrap).The validation problem, however, is solved.