I have a working applicative form, but I want to add a textField that doesn't correspond to any field in my model. Everything is working okay except for one field. Part of my model is a UTCTime value that represents the timestamp of uploading. With applicative forms I had the following code:
-- some stuff
<*> aformM (liftIO getCurrentTime)
-- more stuff
and I can't seem to find the equivalent to aformM for monadic forms. I tried the following:
(timeRes, timeView) <- mformM (liftIO getCurrentTime)
hoping that there would be an equivalent function for monadic forms, similarly to how we have areq/mreq, aopt/mopt, etc., but my code wouldn't compile. So, my question is: is there a way to get the current timestamp using monadic forms?
usually an update timestamp doesn't require to be shown, so in an MForm monad you just pick the value and add it to the applicative result.
currentTime <- liftIO getCurrentTime
(field1_Res, field1_View) <- mreq ...
let myRecord_Res = MyRecord <$> pure currentTime <*> field1_Res <*> field2_Res <*> ...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With