Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dropdown Map becomes empty only when deployed #454

Open
augyg opened this issue May 18, 2023 · 1 comment
Open

Dropdown Map becomes empty only when deployed #454

augyg opened this issue May 18, 2023 · 1 comment

Comments

@augyg
Copy link

augyg commented May 18, 2023

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
Copy link
Author

augyg commented Mar 13, 2024

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
`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant