~alcinnz/amphiarao

ea181da2a6b756e80efdd78197de77d51edb2adc — Adrian Cochrane 3 years ago c2bd1a2
Add support for <select> in forms.
1 files changed, 10 insertions(+), 1 deletions(-)

M src/Internal/Load.hs
M src/Internal/Load.hs => src/Internal/Load.hs +10 -1
@@ 190,6 190,14 @@ clickEl' session (XML.Element (XML.Name name _ _) attrs _) cursor
    | name == "input", Just "checkbox" <- "type" `M.lookup` attrs',
            Just name <- "name" `M.lookup` attrs', Just value <- "value" `M.lookup` attrs' =
        modifyForm (toggleOption value) name cursor session
    -- TODO implement datalists...
    | name == "option", (select:_) <- XC.parent cursor,
            XML.NodeElement select'@(XML.Element "select" attrs2 _) <- XC.node select,
            let attrs2' = M.mapKeys XML.nameLocalName attrs2,
            Just name <- "name" `M.lookup` attrs2, Just value <- "value" `M.lookup` attrs' =
        if "multiple" `M.member` attrs2'
        then modifyForm (toggleOption value) name cursor session
        else modifyForm (const [value]) name cursor session
    | otherwise = return ()
  where
    attrs' = M.mapKeys XML.nameLocalName attrs


@@ 200,9 208,10 @@ clickEl' session (XML.Element (XML.Name name _ _) attrs _) cursor
isClickableEl :: XC.Cursor -> Bool
isClickableEl el | XML.NodeElement el' <- XC.node el = isClickableEl' el'
    | otherwise = False
isClickableEl' (XML.Element _ attrs _)
isClickableEl' (XML.Element name attrs _)
    | Just href <- "href" `M.lookup` attrs', Just _ <- URI.parseURIReference $ Txt.unpack href = True
    | Just src <- "src" `M.lookup` attrs', Just _ <- URI.parseURIReference $ Txt.unpack src = True
    | name `elem` ["input", "label", "button", "option"] = True
    | otherwise = False
  where attrs' = M.mapKeys XML.nameLocalName attrs