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

Forms: form-actions don't close over variables in original form-handler call #16

Closed
MarcKaufmann opened this issue Feb 11, 2021 · 1 comment
Assignees
Labels
async bug Something isn't working

Comments

@MarcKaufmann
Copy link
Owner

We use (form a-form an-action a-renderer) to create forms. The action should be taken upon a valid form submission. Suppose we have the following:

(define (handler some-argument)
  (define n (random 10))
  (define a-form ...) ; asks to guess the number
  (define (an-action guessed-number)
    (if (= n guessed-number) (put 'success? #true) (put 'success? #false)))
  (define (a-renderer rw) ...)
  (form a-form an-action a-renderer))

Then after submission of the form with a guessed-number, the handler is called again, which generates a new n. If a valid guess was provided, it then compares the guessed-number against this new value of n, not the original one -- which is of course not the intended behavior.

How can we fix this?

@MarcKaufmann MarcKaufmann added the help wanted Extra attention is needed label Feb 11, 2021
@Bogdanp
Copy link
Collaborator

Bogdanp commented Feb 11, 2021

For next session: require that handlers return pages. Those pages can then capture the current renderer for each handler, which forms can then re-use w/o re-running the other code in the handler. Effectively, page is when the "response" part of a handler starts and it should be re-runnable.

@MarcKaufmann MarcKaufmann added async bug Something isn't working and removed help wanted Extra attention is needed labels Feb 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
async bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants