[racket] formlets with radio button & checkbox example?

From: Jay McCarthy (jay.mccarthy at gmail.com)
Date: Mon Dec 26 16:28:59 EST 2011

Here is a short example:

#lang racket
(require racket/promise

(define some-formlet
   (div "Checked Radio"
        ,{(default #"default" (radio #"checked-radio" #t)) . => . cr}
        "Not-Checked Radio"
        ,{(default #"default" (radio #"unchecked-radio" #f)) . => . ncr}
        "Checked Checkbox"
        ,{(default #"default" (checkbox #"checked-checkbox" #t)) . => . cc}
        "Not-Checked Checkbox"
        ,{(default #"default" (checkbox #"uncheck-checkbox" #f)) . => . ncc})
   (list cr ncr cc ncc)))

(formlet-display some-formlet)

(define (show-example bs)
  (formlet-process some-formlet
                   (request #"GET"
                            (string->url "http://localhost")
                            (delay bs)

(show-example empty)
(show-example (list (binding:form #"input_0" #"true")))
(show-example (list (binding:form #"input_0" #"true")
                    (binding:form #"input_1" #"false")))
(show-example (list (binding:form #"input_0" #"true")
                    (binding:form #"input_1" #"false")
                    (binding:form #"input_2" #"true")
                    (binding:form #"input_3" #"false")))

It would be good to create a higher-level formlet that rendered to a
checkbox or radio button that would return a boolean or a selection,
like the select formlets do.


On Mon, Dec 26, 2011 at 12:02 PM, keydana at gmx.de <keydana at gmx.de> wrote:
> Hi,
> it's me again, and whereas I don't know how dumb I am I sure might have been a bit lazy :-;
> Unfortunately, even after taking a bit more time, I don't know how it works. Lastly, I've been trying this, which displayed fine:
> (define f-choose-db
>  (let ((o (radio #"orcl" #t))
>        (r (radio #"rndba" #f)))
>    (formlet
>     (div "orcl" ,(o . => . orcl)
>          "rndba" ,(r . => . rndba))
>     (values orcl rndba))))
> But when I use formlet-process to extract the result (just clicking submit, leaving the checked box checked), I get the values #<binding:form> and #f... (and see input_0=on in the browser).
> Also I was trying to add a binding name to the radio function calls themselves, e.g. (radio #"xx" #f . => . myname), but this throws a syntax error.
> Could anyone offer a hint what I'm doing wrong here?
> (BTW this list has the most helpful people & inspiring content of all mailing lists I know of , and I'm not writing this in order to get a nice answer :-) )
> Ciao
> Sigrid
> ____________________
>  Racket Users list:
>  http://lists.racket-lang.org/users

Jay McCarthy <jay at cs.byu.edu>
Assistant Professor / Brigham Young University

"The glory of God is Intelligence" - D&C 93

Posted on the users mailing list.