reflex-dom icon indicating copy to clipboard operation
reflex-dom copied to clipboard

Dropdown Map becomes empty only when deployed

Open augyg opened this issue 1 year ago • 1 comments

let mappy = Map.fromList $ fmap (\x -> (x,x)) $ [ "As soon as possible" , "1-2 months" , "3-6 months" , "6+ months" ] dropdown "As soon as possible" (constDyn mappy) def

For this code, it works completely fine when using localhost and when deployed, only gives all options the first time you visit the page however any other time including refreshing the page, the options disappear

Localhost:

image

Deployed: https://aceinterviewpreparation.com/main/onboard

image

When the page is refreshed, the options momentarily show up. I'm using a constDyn for each dropdown

reflex-platform branch "release/0.9.2.0"

augyg avatar May 18 '23 19:05 augyg

here's the code I wrote to avoid this

`-- | TODO: take an element config for the options elements as well -- | TODO: clean up and upstream to reflex-dom-contrib dropdown' :: ( MonadFix m , DomBuilder t m , Ord a ) => Map.Map a T.Text -- TODO: use NonEmpty -> SelectElementConfig er t (DomBuilderSpace m) -> m (Dynamic t a) dropdown' options cfg' = mdo let class' = "w-full px-4 py-3 border border-gray-300 rounded-lg focus:outline-none focus:border-[#00B9DA] font-[Sarabun] text-lg mb-5 bg-white" let safeInitial = (snd . head $ Map.toList options) -- if options == mempty -- then "" -- else -- if _selectElementConfig_initialValue cfg == "" -- then _selectElementConfig_initialValue cfg -- else (snd . head $ Map.toList options)

let cfg = cfg' & selectElementConfig_initialValue .~ safeInitial & selectElementConfig_setValue .~ optionsEvent & selectElementConfig_elementConfig . elementConfig_initialAttributes .~ ("class" =: class') (selectEl, optionsEvent) <- selectElement cfg $ do optionsEv <- mapM makeOpt $ fmap snd $ Map.toList options pure $ leftmost optionsEv let options' = Map.fromList $ fmap flipTup $ Map.toList options pure $ fmap (\v -> fromJust $ Map.lookup v options') $ _selectElement_value selectEl where flipTup (a,b) = (b,a) makeOpt optText = do (e, _) <- elAttr' "option" ("value" =: optText) $ text optText pure $ optText <$ domEvent Click e

dropdownWithDefault :: ( MonadFix m , DomBuilder t m , Ord a ) => Map.Map a T.Text -> T.Text -> SelectElementConfig er t (DomBuilderSpace m) -> m (Dynamic t a) dropdownWithDefault options start cfg' = mdo let class' = "w-full px-4 py-3 border border-gray-300 rounded-lg focus:outline-none focus:border-[#00B9DA] font-[Sarabun] text-lg mb-5 bg-white" let safeInitial = start -- (snd . head $ Map.toList options) let cfg = cfg' & selectElementConfig_initialValue .~ safeInitial & selectElementConfig_setValue .~ optionsEvent & selectElementConfig_elementConfig . elementConfig_initialAttributes .~ ("class" =: class') (selectEl, optionsEvent) <- selectElement cfg $ do optionsEv <- mapM makeOpt $ fmap snd $ Map.toList options pure $ leftmost optionsEv let options' = Map.fromList $ fmap flipTup $ Map.toList options pure $ fmap (\v -> fromJust $ Map.lookup v options') $ _selectElement_value selectEl where flipTup (a,b) = (b,a) makeOpt optText = do (e, _) <- elAttr' "option" ("value" =: optText) $ text optText pure $ optText <$ domEvent Click e `

augyg avatar Mar 13 '24 02:03 augyg