@@ -16,6 +16,7 @@ import GHCJS.DOM.HTMLTextAreaElement (HTMLTextAreaElement, castToHTMLTextAreaEle
16import GHCJS.DOM.HTMLSelectElement (castToHTMLSelectElement)
16import GHCJS.DOM.HTMLSelectElement (castToHTMLSelectElement)
17import qualified GHCJS.DOM.HTMLSelectElement as HTMLSelectElement
17import qualified GHCJS.DOM.HTMLSelectElement as HTMLSelectElement
18import Data.Maybe
18import Data.Maybe
19+import qualified Text.Read as T
19import Data.Semigroup
20import Data.Semigroup
20import Control.Monad.Fix
21import Control.Monad.Fix
21import Control.Monad.IO.Class
22import Control.Monad.IO.Class
@@ -418,7 +419,7 @@ regularToDropdownViewEventType en r = case en of
418--TODO: We should allow the user to specify an ordering instead of relying on the ordering of the Map
419--TODO: We should allow the user to specify an ordering instead of relying on the ordering of the Map
419-- | Create a dropdown box
420-- | Create a dropdown box
420-- The first argument gives the initial value of the dropdown; if it is not present in the map of options provided, it will be added with an empty string as its text
421-- The first argument gives the initial value of the dropdown; if it is not present in the map of options provided, it will be added with an empty string as its text
421−dropdown :: forall k t m. (DomBuilder t m, MonadFix m, MonadHold t m, PerformEvent t m, MonadIO (Performable m), PostBuild t m, DomBuilderSpace m ~ GhcjsDomSpace, Ord k) => k -> Dynamic t (Map k Text) -> DropdownConfig t k -> m (Dropdown t k)
422+dropdown :: forall k t m. (DomBuilder t m, MonadFix m, MonadHold t m, PerformEvent t m, MonadIO (Performable m), MonadIO m, TriggerEvent t m, PostBuild t m, DomBuilderSpace m ~ GhcjsDomSpace, Ord k) => k -> Dynamic t (Map k Text) -> DropdownConfig t k -> m (Dropdown t k)
422dropdown k0 options (DropdownConfig setK attrs) = do
423dropdown k0 options (DropdownConfig setK attrs) = do
423 optionsWithAddedKeys <- combineDyn Map.union options <=< foldDyn Map.union (k0 =: "") $ fmap (=: "") setK
424 optionsWithAddedKeys <- combineDyn Map.union options <=< foldDyn Map.union (k0 =: "") $ fmap (=: "") setK
424 defaultKey <- holdDyn k0 setK
425 defaultKey <- holdDyn k0 setK
@@ -447,7 +448,7 @@ dropdown k0 options (DropdownConfig setK attrs) = do
447 elDynAttr "option" optionAttrs $ dynText v
448 elDynAttr "option" optionAttrs $ dynText v
448 let e = castToHTMLSelectElement $ _element_raw eRaw
449 let e = castToHTMLSelectElement $ _element_raw eRaw
449 performEvent_ $ fmap (HTMLSelectElement.setValue e . Just . show) $ attachDynWithMaybe (flip Bimap.lookupR) ixKeys setK
450 performEvent_ $ fmap (HTMLSelectElement.setValue e . Just . show) $ attachDynWithMaybe (flip Bimap.lookupR) ixKeys setK
450− eChange <- return never -- attachDynWith (\ks s -> join $ Bimap.lookup <$> join (readMaybe <$> s) <*> pure ks) ixKeys <$> (wrapDomEvent e (`on` Element.change) $ HTMLSelectElement.getValue e)
451+ eChange <- attachDynWith (\ks s -> join $ Bimap.lookup <$> join (T.readMaybe <$> s) <*> pure ks) ixKeys <$> (wrapDomEvent e (`on` Element.change) $ HTMLSelectElement.getValue e)
451 let readKey keys mk = fromMaybe k0 $ do
452 let readKey keys mk = fromMaybe k0 $ do
453 guard $ Bimap.memberR k keys
454 guard $ Bimap.memberR k keys