jaspervdj / digestive-functors

A general way to consume input using applicative functors
149 stars 71 forks source link

how can i change a value in a view? #121

Open DanielCollins opened 9 years ago

DanielCollins commented 9 years ago

after using postForm, if there are form errors, i get a view value. I cannot work out how to reset some of the form values held in the view before re-displaying the form. Specifically, my captcha should be regenerated with each request so as to prevent unlimited captcha attempts.

winterland1989 commented 9 years ago

I came across the exactly problem as yours, here 's my solution:

import           Text.Digestive.Types
import           Text.Digestive.View
...
lform <- getForm "profile" (profileForm u')
let lform' = lform {viewInput = [
    (toPath "email", TextInput $ sUserEmail user)
    ,   (toPath "desc", TextInput $ sUserDesc user)
    ]}
...

Not nice but do solve the problem, we should providing a helper to do this kind of things, for example, set some pre-defined values in views.

DanielCollins commented 9 years ago

thanks @winterland1989 this is workable

winterland1989 commented 9 years ago

@jaspervdj Do you think we should add some APIs to poke around view?

jaspervdj commented 8 years ago

Yes, I wouldn't mind having an API which allows you to set these values in a more convenient way.