Closed mavenraven closed 10 years ago
I've just been passing in the data as an argument to the form:
addressForm :: Monad m => Maybe Address -> Form Text m Address
addressForm a = monadic $ do
stateChoices <- getStatesFromDB
countryChoices <- getCountriesFromDB
return $
Address
<$> "name" .: optionalString (name =<< a)
<*> "street" .: string (street <$> a)
<*> "city" .: string (city <$> a)
<*> "state" .: choiceWith stateChoices (state <$> a)
<*> "country" .: choiceWith countryChoices (country <$> a)
<*> "zipcode" .: string (zipcode <$> a)
Yeah, this is exactly what the formlet type alias is for.
Oh yeah, that makes perfect sense, thanks for the help all!
So, I'm working on a form that edits data that has already been saved to the database. Right now, I'm just manually splicing in the data with heist, but that kind of falls apart with my sum type / drop down mapping. I could dump the data into the text form digestive functor likes (e.g. "form.name=hello&form.field=bye..."), but I was thinking that there might be a nicer way to do that that I can't figure out, since it seems like a common use case? If not, I was thinking of adding something like
to digestive functors.