* I have boiled down my problem to the minimal example at the end of the 
post

* Basically, I'm running a formlet form in 'cycles' on itself to filter 
some list data

* on the initial invocation, the bindings in the request are empty, as 
expected:
request bindings: ()
stop: #f, use-name-filter?: #f, name-filter: #f

* submitting the form without selecting a list item results in the binding 
for the list to be missing (hence a contract violation on parsing by 
formlet-process, which results in default values):
request bindings: (#(struct:binding:form input_1 ) #(struct:binding:form 
input_2 ))
stop: #f, use-name-filter?: #f, name-filter: #f

* even when selecting a list item, the other values are not bound to their 
'control values' (boolean and string), but to the binding:form structs:
request bindings: (#(struct:binding:form input_0 0) #(struct:binding:form 
input_1 ) #(struct:binding:form input_2 abc))
stop: #<stop>, use-name-filter?: #(struct:binding:form input_1 ), 
name-filter: #(struct:binding:form input_2 abc)

* (the problem is the same with a different handler for the submit button, 
without the form returning to itself)

* Any suggestions on what I most probably misunderstand would be welcome.

Thanks for your consideration,
Christian

Example:

#lang web-server/insta

(require web-server/http/bindings)
(require web-server/formlets)
(require web-server/formlets/input)

(struct stop (id name))

(define stops (list (stop 1 "Foo")
                    (stop 2 "Bar")
                    (stop 3 "Baz")))

(define (start request)
  (render-info-page request))

(define form-formlet
  (formlet
   (#%# (div ,{(select-input stops
                             #:attributes '((size "40"))
                             #:display (lambda (stop)
                                         (stop-name stop))) . => . stop})
        (div ,{(checkbox "" #t) . => . use-name-filter?}
             "Name filter "
             ,{(text-input) . => . name-filter}))
   (values stop use-name-filter? name-filter)))

(define (render-info-page request)
  (printf "request bindings: ~a~n" (force (request-bindings/raw-promise 
request)))
  (define-values (stop use-name-filter? name-filter)
    (with-handlers ([(lambda (e) #t) (lambda (e) (values #f #f #f))])
      (formlet-process form-formlet request)))
  (printf "stop: ~a, use-name-filter?: ~a, name-filter: ~a~n" stop 
use-name-filter? name-filter)
  (define (response-generator embed/url)
    (response/xexpr
     `(html
       (head (title "Stop Info"))
       (body (h1 "List of Stops")
             (h2 ,(if stop
                      (stop-name stop)
                      "no stop selected"))
             (form ([action ,(embed/url render-info-page)])
                   ,@(formlet-display form-formlet)
                   (p (input ([type "submit"]))))
             ))))
  (send/suspend/dispatch response-generator))

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to