on develop help sign in
Avoid the use of sample in order to ease debugging
f81d943leon.smith@obsidian.systems
reflex-dom-core/src/Reflex/Dom/Widget/Input.hs+5−4
@@ -437,12 +437,13 @@ dropdown k0 options (DropdownConfig setK attrs) = do
437 let xs = fmap (\(ix, (k, v)) -> ((ix, k), ((ix, k), v))) $ zip [0::Int ..] $ Map.toList os
437 let xs = fmap (\(ix, (k, v)) -> ((ix, k), ((ix, k), v))) $ zip [0::Int ..] $ Map.toList os
438 in (Map.fromList $ map snd xs, Bimap.fromList $ map fst xs)
438 in (Map.fromList $ map snd xs, Bimap.fromList $ map fst xs)
439 modifyAttrs <- dynamicAttributesToModifyAttributes attrs
439 modifyAttrs <- dynamicAttributesToModifyAttributes attrs
440− initialIxKeys <- sample $ current ixKeys
440+ postBuild <- getPostBuild
441− let initialValue = maybe "" (T.pack . show) $ Bimap.lookupR k0 initialIxKeys
441+ let updatedSelection = attachPromptlyDynWithMaybe (flip Bimap.lookupR) ixKeys setK
442+ initialSelection = attachPromptlyDynWithMaybe (flip Bimap.lookupR) ixKeys (k0 <$ postBuild)
443+ selection = leftmost [updatedSelection, initialSelection]
442 let cfg = def
444 let cfg = def
443 & selectElementConfig_elementConfig . elementConfig_modifyAttributes .~ fmap mapKeysToAttributeName modifyAttrs
445 & selectElementConfig_elementConfig . elementConfig_modifyAttributes .~ fmap mapKeysToAttributeName modifyAttrs
444− & selectElementConfig_setValue .~ fmap (T.pack . show) (attachPromptlyDynWithMaybe (flip Bimap.lookupR) ixKeys setK)
446+ & selectElementConfig_setValue .~ fmap (T.pack . show) selection
445− & selectElementConfig_initialValue .~ initialValue
446 (eRaw, _) <- selectElement cfg $ listWithKey indexedOptions $ \(ix, k) v -> do
447 (eRaw, _) <- selectElement cfg $ listWithKey indexedOptions $ \(ix, k) v -> do
447 let optionAttrs = fmap (\dk -> "value" =: T.pack (show ix) <> if dk == k then "selected" =: "selected" else mempty) defaultKey
448 let optionAttrs = fmap (\dk -> "value" =: T.pack (show ix) <> if dk == k then "selected" =: "selected" else mempty) defaultKey
448 elDynAttr "option" optionAttrs $ dynText v
449 elDynAttr "option" optionAttrs $ dynText v