Merge pull request #1510 from bsima/form-fns
Move 'addClass' to Yesod.Form.Functions and add 'removeClass'
This commit is contained in:
commit
1cf2f56918
@ -1,3 +1,8 @@
|
||||
## 1.6.2
|
||||
|
||||
* Move `addClass` from private/undocumented in `Yesod.Form.Bootstrap3` to `Yesod.Form.Functions` [#1510](https://github.com/yesodweb/yesod/pull/1510)
|
||||
* Add `Yesod.Form.Functions.removeClass` [#1510](https://github.com/yesodweb/yesod/pull/1510)
|
||||
|
||||
## 1.6.1
|
||||
|
||||
* Explicitly define `(<>)` in the `Semigroup` instance for `Enctype`
|
||||
|
||||
@ -33,9 +33,6 @@ import Control.Monad (liftM)
|
||||
import Data.Text (Text)
|
||||
import Data.String (IsString(..))
|
||||
import Yesod.Core
|
||||
|
||||
import qualified Data.Text as T
|
||||
|
||||
import Yesod.Form.Types
|
||||
import Yesod.Form.Functions
|
||||
|
||||
@ -82,12 +79,6 @@ withSmallInput fs = fs { fsAttrs = newAttrs }
|
||||
where newAttrs = addClass "input-sm" (fsAttrs fs)
|
||||
|
||||
|
||||
addClass :: Text -> [(Text, Text)] -> [(Text, Text)]
|
||||
addClass klass [] = [("class", klass)]
|
||||
addClass klass (("class", old):rest) = ("class", T.concat [old, " ", klass]) : rest
|
||||
addClass klass (other :rest) = other : addClass klass rest
|
||||
|
||||
|
||||
-- | How many bootstrap grid columns should be taken (see
|
||||
-- 'BootstrapFormLayout').
|
||||
--
|
||||
|
||||
@ -51,10 +51,13 @@ module Yesod.Form.Functions
|
||||
, parseHelper
|
||||
, parseHelperGen
|
||||
, convertField
|
||||
, addClass
|
||||
, removeClass
|
||||
) where
|
||||
|
||||
import Yesod.Form.Types
|
||||
import Data.Text (Text, pack)
|
||||
import qualified Data.Text as T
|
||||
import Control.Arrow (second)
|
||||
import Control.Monad.Trans.Class
|
||||
import Control.Monad.Trans.RWS (ask, get, put, runRWST, tell, evalRWST, local, mapRWST)
|
||||
@ -615,3 +618,33 @@ convertField to from (Field fParse fView fEnctype) = let
|
||||
fParse' ts = fmap (fmap (fmap to)) . fParse ts
|
||||
fView' ti tn at ei = fView ti tn at (fmap from ei)
|
||||
in Field fParse' fView' fEnctype
|
||||
|
||||
-- | Removes a CSS class from the 'fsAttrs' in a 'FieldSettings'.
|
||||
--
|
||||
-- ==== __Examples__
|
||||
--
|
||||
-- >>> removeClass "form-control" [("class","form-control login-form"),("id","home-login")]
|
||||
-- [("class"," login-form"),("id","home-login")]
|
||||
--
|
||||
-- @since 1.6.2
|
||||
removeClass :: Text -- ^ The class to remove
|
||||
-> [(Text, Text)] -- ^ List of existing 'fsAttrs'
|
||||
-> [(Text, Text)]
|
||||
removeClass _ [] = []
|
||||
removeClass klass (("class", old):rest) = ("class", T.replace klass " " old) : rest
|
||||
removeClass klass (other :rest) = other : removeClass klass rest
|
||||
|
||||
-- | Adds a CSS class to the 'fsAttrs' in a 'FieldSettings'.
|
||||
--
|
||||
-- ==== __Examples__
|
||||
--
|
||||
-- >>> addClass "login-form" [("class", "form-control"), ("id", "home-login")]
|
||||
-- [("class","form-control login-form"),("id","home-login")]
|
||||
--
|
||||
-- @since 1.6.2
|
||||
addClass :: Text -- ^ The class to add
|
||||
-> [(Text, Text)] -- ^ List of existing 'fsAttrs'
|
||||
-> [(Text, Text)]
|
||||
addClass klass [] = [("class", klass)]
|
||||
addClass klass (("class", old):rest) = ("class", T.concat [old, " ", klass]) : rest
|
||||
addClass klass (other :rest) = other : addClass klass rest
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
name: yesod-form
|
||||
version: 1.6.1
|
||||
version: 1.6.2
|
||||
license: MIT
|
||||
license-file: LICENSE
|
||||
author: Michael Snoyman <michael@snoyman.com>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user