reflex-frp / reflex-dom

Web applications without callbacks or side-effects. Reflex-DOM brings the power of functional reactive programming (FRP) to the web. Build HTML and other Document Object Model (DOM) data with a pure functional interface.
https://reflex-frp.org
BSD 3-Clause "New" or "Revised" License
357 stars 145 forks source link

dropdown value never change #85

Closed montagy closed 8 years ago

montagy commented 8 years ago
{-# LANGUAGE OverloadedStrings #-}
import Reflex
import Reflex.Dom
import Data.Monoid
import Control.Monad.IO.Class

data Color = Red|Blue|Yellow deriving (Show, Enum, Eq, Ord)
main :: IO ()
main = mainWidget $ do
  drop <- dropdown Red (constDyn $ Red =: "red" <> Blue =: "blue" <> Yellow =: "yellow") def
  submit <- button "submit"
  let s = tagPromptlyDyn (value drop) submit
  performEvent_ $ (liftIO . print) <$> s

you will always see "Red" when the submit clicked whatever the select is.

mrijkeboer commented 8 years ago

I'm having the same problem. It looks like the Dynamic is not updated, it remains the default "Active" value.

{-# LANGUAGE OverloadedStrings #-}

import ClassyPrelude
import Data.Default (def)
import Reflex.Dom

dropdownTest :: MonadWidget t m => m ()
dropdownTest = do
    val <- recordActiveWidget
    dynText $ _dropdown_value val

recordActiveWidget :: MonadWidget t m => m (Dropdown t Text)
recordActiveWidget = do
    let values = constDyn (("Active" =: "Active") <> ("Inactive" =: "Inactive"))
    dropdown "Active" values def

I'm using the develop branch for both reflex and reflex-dom.

ryantrinkle commented 8 years ago

Hi @montagy, @mrijkeboer; thanks for reporting this. I'll look into it ASAP.

mulderr commented 8 years ago

I can also reproduce using reflex-platform HEAD.

Don't know if this will be helpful but it looks like for reflex-platform this was introduced in e570691810166e476d88002950ce16c72a8dd7d2. It does not occur for the previous commit d9eab5065319a5575456d4e472df9024987c497f.

> git diff d9eab5065319a5575456d4e472df9024987c497f e570691810166e476d88002950ce16c72a8dd7d2                                    ~/src/reflex-platform
diff --git a/reflex-dom/github.json b/reflex-dom/github.json
index 44cc2fa..d4f92bc 100644
--- a/reflex-dom/github.json
+++ b/reflex-dom/github.json
@@ -1,6 +1,6 @@
 {
   "owner": "reflex-frp",
   "repo": "reflex-dom",
-  "rev": "d8cb71eb82e18a0ab316cbf108712d042f88bc3b",
-  "sha256": "04djim3lkxhfrh9xb1bgpaclhjr6hjcd54msfv574pi6y80isbdi"
+  "rev": "68e10ee7e368ac42b397d6efb898be2606712b00",
+  "sha256": "0swvxbfw1qsgpm00xvkdqnb414sc8q6591gv0227gmag8cmmaig7"
 }
ryantrinkle commented 8 years ago

Hey @montagy, @mrijkeboer, @mulderr:

Whoops, it looks like I used the wrong event to get the dropdown changes! Fixed, and a new reflex-platform (0e88a9c4590bf76574875c1615ae24c0ce0f4cc6) should be pushed soon with the fix.

mrijkeboer commented 8 years ago

Hey @ryantrinkle:

This change fixes the issue. Thanks.