on develop help sign in
Add initial value to SelectElementConfiguration in dropdown
4873bcaleon.smith@obsidian.systems
reflex-dom-core/src/Reflex/Dom/Widget/Input.hs+3
@@ -437,9 +437,12 @@ 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
441+ let initialValue = maybe "" (T.pack . show) $ Bimap.lookupR k0 initialIxKeys
440 let cfg = def
442 let cfg = def
441 & selectElementConfig_elementConfig . elementConfig_modifyAttributes .~ fmap mapKeysToAttributeName modifyAttrs
443 & selectElementConfig_elementConfig . elementConfig_modifyAttributes .~ fmap mapKeysToAttributeName modifyAttrs
442 & selectElementConfig_setValue .~ fmap (T.pack . show) (attachPromptlyDynWithMaybe (flip Bimap.lookupR) ixKeys setK)
444 & selectElementConfig_setValue .~ fmap (T.pack . show) (attachPromptlyDynWithMaybe (flip Bimap.lookupR) ixKeys setK)
445+ & selectElementConfig_initialValue .~ initialValue
443 (eRaw, _) <- selectElement cfg $ listWithKey indexedOptions $ \(ix, k) v -> do
446 (eRaw, _) <- selectElement cfg $ listWithKey indexedOptions $ \(ix, k) v -> do
444 let optionAttrs = fmap (\dk -> "value" =: T.pack (show ix) <> if dk == k then "selected" =: "selected" else mempty) defaultKey
447 let optionAttrs = fmap (\dk -> "value" =: T.pack (show ix) <> if dk == k then "selected" =: "selected" else mempty) defaultKey
445 elDynAttr "option" optionAttrs $ dynText v
448 elDynAttr "option" optionAttrs $ dynText v