Context
I have a view with a form with an arbitrary number of inputs that are dynamically generated by a controller. When the form is submitted, each input should create its own record, so that if there are 60 inputs then 60 records should be made.
Question
How should one validate each of the inputs/fields? In the examples in the IHP documentation, only 1 record is created by a single form so I am not sure what is the best or idiomatic way to do this.
Possibly I could map a function like the following to every submitted input, but the Left case would be triggered by the first validation failure rather than all validation failures so I would need to save each failure in a list (?) before redirecting to the previous form view.
action CreatePostAction = do
let post = newRecord @Post
post
|> fill @'["title", "body"]
|> validateField #title nonEmpty
|> validateField #body nonEmpty
|> ifValid \case
Left post -> render NewView { post }
Right post -> do
post <- post |> createRecord
setSuccessMessage "Post created"
redirectTo PostsAction