Happstack / reform

reform is type-safe HTML form generation and validation library
BSD 3-Clause "New" or "Revised" License
4 stars 2 forks source link

How to populate a form from a datum? #5

Closed ghost closed 6 years ago

ghost commented 6 years ago

Reform nicely handles these use cases:

However I haven't figured out how to achieve this use case:

Is there such a feature in Reform?

ghost commented 6 years ago

Based on this thread in digestive-functors, this functionality seems to be covered by NoEnvironment constructor for Environment, which allows you to use injected info from the form definition.

stepcut commented 6 years ago

This could be more clearly documented.

If you look at a function like inputText it allows you to provide the initial value,

http://hackage.haskell.org/package/reform-hsp-0.2.7.1/docs/Text-Reform-HSP-Text.html

So if you look at a function like this pageFormlet you'll see it takes a Page and returns the modified Page,

https://github.com/clckwrks/clckwrks-plugin-page/blob/master/Clckwrks/Page/Admin/EditPage.hs#L52

If you peer through the ugliness you'll see that the initial form values are extracted from the page value,

 textarea 80 25 (markup (pageSrc page))

This is clearly something that should be shown more explicitly in this tutorial,

http://happstack.com/docs/crashcourse/Reform.html#reform