yesodweb/yesod — Issue #240: yesod-form: generalize some fields to RenderMessage
Author: meteficha
Created: 2012-01-25 16:21:49+00:00
State: open

Currently we have:

```haskell
selectFieldList :: (Eq a, RenderMessage master FormMessage) => [(Text, a)] -> Field sub master a
multiSelectFieldList :: (Eq a, RenderMessage master FormMessage) => [(Text, a)] -> Field sub master [a]
radioFieldList :: (Eq a, RenderMessage master FormMessage) => [(Text, a)] -> Field sub master a
optionsPairs :: [(Text, a)] -> GHandler sub master (OptionList a)

optionsPersist :: ( YesodPersist master, PersistEntity a
, PersistQuery (YesodPersistBackend master) (GHandler sub master)
, PathPiece (Key (YesodPersistBackend master) a)
)
=> [Filter a] -> [SelectOpt a] -> (a -> Text) -> GHandler sub master (OptionList (Entity (YesodPersistBackend master) a))
```

All of these functions take `Text`s as parameters in order to put them on the template. However, on an i18n-ready site most of these `Text`s need to translated, so these functions can't be directly used. I propose generalizing them to

```haskell
selectFieldList :: (Eq a, RenderMessage master FormMessage, RenderMessage master msg) => [(msg, a)] -> Field sub master a
multiSelectFieldList :: (Eq a, RenderMessage master FormMessage, RenderMessage master msg) => [(msg, a)] -> Field sub master [a]
radioFieldList :: (Eq a, RenderMessage master FormMessage, RenderMessage master msg) => [(msg, a)] -> Field sub master a
optionsPairs :: (RenderMessage master msg) => [(msg, a)] -> GHandler sub master (OptionList a)

optionsPersist :: ( YesodPersist master, PersistEntity a
, PersistQuery (YesodPersistBackend master) (GHandler sub master)
, PathPiece (Key (YesodPersistBackend master) a)
, RenderMessage master msg
)
=> [Filter a] -> [SelectOpt a] -> (a -> msg) -> GHandler sub master (OptionList (Entity (YesodPersistBackend master) a))
```

Note that `instance RenderMessage master Text` holds for all `master`s, so old code continues to run with these generalized type signatures.

Thoughts?