Handle labels containing inputs #759
This commit is contained in:
parent
382a5402c8
commit
ef25c90e9b
@ -421,10 +421,10 @@ nameFromLabel label = do
|
|||||||
Just res -> return res
|
Just res -> return res
|
||||||
let
|
let
|
||||||
body = simpleBody res
|
body = simpleBody res
|
||||||
mfor = parseHTML body
|
mlabel = parseHTML body
|
||||||
$// C.element "label"
|
$// C.element "label"
|
||||||
>=> contentContains label
|
>=> contentContains label
|
||||||
>=> attribute "for"
|
mfor = mlabel >>= attribute "for"
|
||||||
|
|
||||||
contentContains x c
|
contentContains x c
|
||||||
| x `T.isInfixOf` T.concat (c $// content) = [c]
|
| x `T.isInfixOf` T.concat (c $// content) = [c]
|
||||||
@ -444,8 +444,11 @@ nameFromLabel label = do
|
|||||||
, " which was not found. "
|
, " which was not found. "
|
||||||
]
|
]
|
||||||
name:_ -> return name
|
name:_ -> return name
|
||||||
_ -> failure $ "More than one input with id " <> for
|
[] -> failure $ "No input with id " <> for
|
||||||
[] -> failure $ "No label contained: " <> label
|
[] ->
|
||||||
|
case filter (/= "") $ mlabel >>= (child >=> C.element "input" >=> attribute "name") of
|
||||||
|
[] -> failure $ "No label contained: " <> label
|
||||||
|
name:_ -> return name
|
||||||
_ -> failure $ "More than one label contained " <> label
|
_ -> failure $ "More than one label contained " <> label
|
||||||
|
|
||||||
(<>) :: T.Text -> T.Text -> T.Text
|
(<>) :: T.Text -> T.Text -> T.Text
|
||||||
|
|||||||
@ -132,6 +132,14 @@ main = hspec $ do
|
|||||||
get ("/dynamic2/שלום" :: Text)
|
get ("/dynamic2/שלום" :: Text)
|
||||||
statusIs 200
|
statusIs 200
|
||||||
bodyEquals "שלום"
|
bodyEquals "שלום"
|
||||||
|
|
||||||
|
ydescribe "labels" $ do
|
||||||
|
yit "can click checkbox" $ do
|
||||||
|
get ("/labels" :: Text)
|
||||||
|
request $ do
|
||||||
|
setMethod "POST"
|
||||||
|
setUrl ("/labels" :: Text)
|
||||||
|
byLabel "Foo Bar" "yes"
|
||||||
describe "cookies" $ yesodSpec cookieApp $ do
|
describe "cookies" $ yesodSpec cookieApp $ do
|
||||||
yit "should send the cookie #730" $ do
|
yit "should send the cookie #730" $ do
|
||||||
get ("/" :: Text)
|
get ("/" :: Text)
|
||||||
@ -174,6 +182,9 @@ app = liteApp $ do
|
|||||||
onStatic "html" $ dispatchTo $
|
onStatic "html" $ dispatchTo $
|
||||||
return ("<html><head><title>Hello</title></head><body><p>Hello World</p><p>Hello Moon</p></body></html>" :: Text)
|
return ("<html><head><title>Hello</title></head><body><p>Hello World</p><p>Hello Moon</p></body></html>" :: Text)
|
||||||
|
|
||||||
|
onStatic "labels" $ dispatchTo $
|
||||||
|
return ("<html><label><input type='checkbox' name='fooname' id='foobar'>Foo Bar</label></html>" :: Text)
|
||||||
|
|
||||||
|
|
||||||
cookieApp :: LiteApp
|
cookieApp :: LiteApp
|
||||||
cookieApp = liteApp $ do
|
cookieApp = liteApp $ do
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
name: yesod-test
|
name: yesod-test
|
||||||
version: 1.2.3
|
version: 1.2.3.1
|
||||||
license: MIT
|
license: MIT
|
||||||
license-file: LICENSE
|
license-file: LICENSE
|
||||||
author: Nubis <nubis@woobiz.com.ar>
|
author: Nubis <nubis@woobiz.com.ar>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user