on develop help sign in
Add initial value to SelectElementConfiguration in dropdown
commit4873bca8ccd8a50150b82dc2fed7a5e8acf1b908 authorleon.smith@obsidian.systems <leon.smith@obsidian.systems> dateTue 17 Dec 2019, 14:55 (7 years ago) parentdf46ac9
1 file changed+3
reflex-dom-core/src/Reflex/Dom/Widget/Input.hs+3
reflex-dom-core/src/Reflex/Dom/Widget/Input.hs+3
@@ -437,9 +437,12 @@ 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
440442 let cfg = def
441443 & selectElementConfig_elementConfig . elementConfig_modifyAttributes .~ fmap mapKeysToAttributeName modifyAttrs
442444 & selectElementConfig_setValue .~ fmap (T.pack . show) (attachPromptlyDynWithMaybe (flip Bimap.lookupR) ixKeys setK)
445+ & selectElementConfig_initialValue .~ initialValue
443446 (eRaw, _) <- selectElement cfg $ listWithKey indexedOptions $ \(ix, k) v -> do
444447 let optionAttrs = fmap (\dk -> "value" =: T.pack (show ix) <> if dk == k then "selected" =: "selected" else mempty) defaultKey
445448 elDynAttr "option" optionAttrs $ dynText v