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
|
||||
let
|
||||
body = simpleBody res
|
||||
mfor = parseHTML body
|
||||
mlabel = parseHTML body
|
||||
$// C.element "label"
|
||||
>=> contentContains label
|
||||
>=> attribute "for"
|
||||
mfor = mlabel >>= attribute "for"
|
||||
|
||||
contentContains x c
|
||||
| x `T.isInfixOf` T.concat (c $// content) = [c]
|
||||
@ -444,8 +444,11 @@ nameFromLabel label = do
|
||||
, " which was not found. "
|
||||
]
|
||||
name:_ -> return name
|
||||
_ -> failure $ "More than one input with id " <> for
|
||||
[] -> failure $ "No label contained: " <> label
|
||||
[] -> failure $ "No input with id " <> for
|
||||
[] ->
|
||||
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
|
||||
|
||||
(<>) :: T.Text -> T.Text -> T.Text
|
||||
|
||||
@ -132,6 +132,14 @@ main = hspec $ do
|
||||
get ("/dynamic2/שלום" :: Text)
|
||||
statusIs 200
|
||||
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
|
||||
yit "should send the cookie #730" $ do
|
||||
get ("/" :: Text)
|
||||
@ -174,6 +182,9 @@ app = liteApp $ do
|
||||
onStatic "html" $ dispatchTo $
|
||||
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 $ do
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
name: yesod-test
|
||||
version: 1.2.3
|
||||
version: 1.2.3.1
|
||||
license: MIT
|
||||
license-file: LICENSE
|
||||
author: Nubis <nubis@woobiz.com.ar>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user