Thanks for taking the time to try out Formless!
I’m listening to Changed message, but what I’d like is to be able to extract the complete state as a record. It would be cool to have a F.getInputs function.
That would be cool! Unfortunately, I haven’t got anything in the library to help with this yet. There is a helper function in the library called unwrapRecord, which can be used to turn a record of newtypes into a record of the newtype’s contents. For example, here’s how it would work on a form newtype around a record of InputField:
inputs :: Form Record InputField
inputs = Form { a: InputField "hello", b: InputField 10 }
inputs' :: Form Record InputField -> { a :: String, b :: Int }
inputs' = unwrapRecord <<< unwrap
You can use this to get all your form fields as a simple record, which isn’t quite what you’re asking for (rather than { a :: String, b :: Int } you’d have:
{ a :: { input :: String, ... }
, b :: { input :: Int, ... }
}
…but perhaps this gets you a little closer to convenience in the meantime? You can’t quite do fields.a, but you could do fields.a.input instead.
validators is mandatory? What if I’m not validating any field? Is there a way to generate a “dummy” validator in that case?
There will always be a need to provide Formless with a function to get from your input to output type for a field. That doesn’t have to be validation; you could go from an Int input to a String output with hoistFn_ show, with no possible error, for example. In the case that all the form inputs are the same as all the form outputs, I suppose I could support no validation at all and skip that processing! I’ll consider doing so for the next version, 0.3.
In the meantime, you can accomplish the same by providing hoistFn_ identity as the validator for any field that you don’t need validation on. At my company, we wrapped this up as a function called accept :: forall form m i i. Monad m => Validation form m Void i i; accept = hoistFn_ identity. That way we have to specify in our form row that a field has a Void error type so it’s explicit that it cannot fail, and of course that the input and output types are the same.
For example:
validators = MyForm
{ a: accept
, b: hoistFn_ identity
, c: accept
}