on develop help sign in
Avoid the use of sample in order to ease debugging

Requested by John Ericson

commitf81d943e52c9ef2191b43580f5a05ec6ee14675b authorleon.smith@obsidian.systems <leon.smith@obsidian.systems> dateThu 2 Jan 2020, 16:42 (7 years ago) parent4873bca
1 file changed+5−4
reflex-dom-core/src/Reflex/Dom/Widget/Input.hs+5−4
reflex-dom-core/src/Reflex/Dom/Widget/Input.hs+5−4
@@ -437,12 +437,13 @@ dropdown k0 options (DropdownConfig setK attrs) = do
437437 let xs = fmap (\(ix, (k, v)) -> ((ix, k), ((ix, k), v))) $ zip [0::Int ..] $ Map.toList os
438438 in (Map.fromList $ map snd xs, Bimap.fromList $ map fst xs)
439439 modifyAttrs <- dynamicAttributesToModifyAttributes attrs
440− initialIxKeys <- sample $ current ixKeys
441− let initialValue = maybe "" (T.pack . show) $ Bimap.lookupR k0 initialIxKeys
440+ postBuild <- getPostBuild
441+ let updatedSelection = attachPromptlyDynWithMaybe (flip Bimap.lookupR) ixKeys setK
442+ initialSelection = attachPromptlyDynWithMaybe (flip Bimap.lookupR) ixKeys (k0 <$ postBuild)
443+ selection = leftmost [updatedSelection, initialSelection]
442444 let cfg = def
443445 & selectElementConfig_elementConfig . elementConfig_modifyAttributes .~ fmap mapKeysToAttributeName modifyAttrs
444− & selectElementConfig_setValue .~ fmap (T.pack . show) (attachPromptlyDynWithMaybe (flip Bimap.lookupR) ixKeys setK)
445− & selectElementConfig_initialValue .~ initialValue
446+ & selectElementConfig_setValue .~ fmap (T.pack . show) selection
446447 (eRaw, _) <- selectElement cfg $ listWithKey indexedOptions $ \(ix, k) v -> do
447448 let optionAttrs = fmap (\dk -> "value" =: T.pack (show ix) <> if dk == k then "selected" =: "selected" else mempty) defaultKey
448449 elDynAttr "option" optionAttrs $ dynText v