Accumulating form validation -- combine per-field results into one
Validated args where every problem is collected, not just the first.
The applicative sibling of the per-field validation the input atoms
(Web3.Ui.Input, Web3.Ui.Amount) already do.
type alias SendForm =
{ to : T.Address, amount : BigInt }
validated : Model -> Validated SendForm
validated model =
succeed SendForm
|> andMap (fromMaybe "Recipient is not a valid address" model.parsedTo)
|> andMap (fromMaybe "Amount is not a valid number" model.parsedAmount)
-- in view: disable the button and show ALL the problems
button [ disabled (not (Form.isValid v)) ] ...
Form.errorList [] vResult short-circuits on the first Err; forms shouldn't -- a user fixing
a three-field form one error at a time is the classic papercut this type
removes.
CSS classes: web3-form-errors, web3-form-errors__item.
Start a pipeline with the record constructor.
A single failure.
Lift a parsed field: Nothing becomes the given error. The natural
bridge from T.address / BigInt.fromString / Units.parseUnits.
Apply the next field, accumulating errors from both sides.
All accumulated problems (empty when valid).
Render the problems as a list (role="alert"), or nothing when valid.
A value that is either fully valid or carries every accumulated problem.