on develop help sign in
Fix dropdown select event bug
commit5810afc820d594e66c366d862c974ae186cb52a5 authorSid Raval and Luigy Leon <sid.raval@obsidian.systems> dateThu 23 Jun 2016, 10:58 (10 years ago) parent5538d56
1 file changed+3−2
src/Reflex/Dom/Widget/Input.hs+3−2
src/Reflex/Dom/Widget/Input.hs+3−2
@@ -16,6 +16,7 @@ import GHCJS.DOM.HTMLTextAreaElement (HTMLTextAreaElement, castToHTMLTextAreaEle
1616import GHCJS.DOM.HTMLSelectElement (castToHTMLSelectElement)
1717import qualified GHCJS.DOM.HTMLSelectElement as HTMLSelectElement
1818import Data.Maybe
19+import qualified Text.Read as T
1920import Data.Semigroup
2021import Control.Monad.Fix
2122import Control.Monad.IO.Class
@@ -418,7 +419,7 @@ regularToDropdownViewEventType en r = case en of
418419--TODO: We should allow the user to specify an ordering instead of relying on the ordering of the Map
419420-- | Create a dropdown box
420421-- 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)
422423dropdown k0 options (DropdownConfig setK attrs) = do
423424 optionsWithAddedKeys <- combineDyn Map.union options <=< foldDyn Map.union (k0 =: "") $ fmap (=: "") setK
424425 defaultKey <- holdDyn k0 setK
@@ -447,7 +448,7 @@ dropdown k0 options (DropdownConfig setK attrs) = do
447448 elDynAttr "option" optionAttrs $ dynText v
448449 let e = castToHTMLSelectElement $ _element_raw eRaw
449450 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)
451452 let readKey keys mk = fromMaybe k0 $ do
452453 k <- mk
453454 guard $ Bimap.memberR k keys