Do not lose selected value in selectFieldHelper when validation fails

This commit is contained in:
Nickolay Kolev 2018-07-26 14:59:19 +02:00
parent db1ff95520
commit 073c9fabd4
2 changed files with 6 additions and 1 deletions

View File

@ -1,5 +1,10 @@
# ChangeLog for yesod-form # ChangeLog for yesod-form
## Unreleased
* make sure a select field does not lose the selected value even if a validation on the
field fails
## 1.6.2 ## 1.6.2
* Move `addClass` from private/undocumented in `Yesod.Form.Bootstrap3` to `Yesod.Form.Functions` [#1510](https://github.com/yesodweb/yesod/pull/1510) * Move `addClass` from private/undocumented in `Yesod.Form.Bootstrap3` to `Yesod.Form.Functions` [#1510](https://github.com/yesodweb/yesod/pull/1510)

View File

@ -759,7 +759,7 @@ selectFieldHelper outside onOpt inside opts' = Field
, fieldEnctype = UrlEncoded , fieldEnctype = UrlEncoded
} }
where where
render _ (Left _) = "" render _ (Left x) = x
render opts (Right a) = maybe "" optionExternalValue $ listToMaybe $ filter ((== a) . optionInternalValue) opts render opts (Right a) = maybe "" optionExternalValue $ listToMaybe $ filter ((== a) . optionInternalValue) opts
selectParser _ [] = Right Nothing selectParser _ [] = Right Nothing
selectParser opts (s:_) = case s of selectParser opts (s:_) = case s of