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

Monad Formlet & Factoring Out Button #68

Open
nickgeoca opened this issue Oct 18, 2015 · 1 comment
Open

Monad Formlet & Factoring Out Button #68

nickgeoca opened this issue Oct 18, 2015 · 1 comment

Comments

@nickgeoca
Copy link

Description: After the 1st number is entered in the First field, the Second field is populated with "submit". As seen in picture below. The code sample is below too. Note that changing "(Just n1)" to "Nothing" does not change the behavior.
image

Line: n2 <- "Second " ++> getInt (Just n1) <++ br

Version

  • GHC 7.10.2
  • MFlow-0.4.5.11

Code

{-# LANGUAGE OverloadedStrings #-}
module Main
where
import MFlow.Wai.Blaze.Html.All hiding(main)

main = runNavigation "" . step . page . pageFlow "s" $ 
  do  n1 <- "First "  ++> getInt Nothing   <++ br
      n2 <- "Second " ++> getInt (Just n1) <++ br
      p  << (n1 + n2) ++> noWidget

  <** br ++> submitButton "submit"
@nickgeoca nickgeoca changed the title Monad Formlet & Factor out Button Monad Formlet & Factoring Out Button Oct 18, 2015
@agocorona
Copy link
Owner

Nick, for this purposes is the "pageFlow" modifier.

This bad effect is unavoidable in monadic flows when there are alternative
branches and the page is not fully rendered, since the generator of field
identifiers assign them sequentially and the values are filled from the
previous interactions. `pageFlow´ add a prefix that prevent the new fields
to be populated with values from other branches.

when the second getInt is rendered for the first time, it receives the
identifier "p1" but this "p1" was in the previously the identifier of
the submitButton field, that had "submit" as value, so the generator
wrongly assign this to the second sum field. But this is unavoidable unless
submitButton is preceded with apageFlow` prefix, so that the identifier
generated for this field do not clash with the ones of the sum:

main = runNavigation "" . step . page . pageFlow "s" $
  do  n1 <- "First "  ++> getInt Nothing   <++ br
      n2 <- "Second " ++> getInt (Just n1) <++ br
      p  << (n1 + n2) ++> noWidget

  <** br ++> pageFlow "button" (submitButton "submit")

In this example, the submintButton field receive the identifier
"submitp0" the first time that it is rendered, so there is no clash with
the monadic expression above. the zero is because pageFlowalso restart
the field counter for the branch.

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

2 participants