[racket] playing with formlets: vertical radio buttons

From: Dmitry Pavlov (dpavlov at ipa.nw.ru)
Date: Mon Dec 9 14:02:06 EST 2013


I recently started to write in Racket a simple web page.

The page has radio buttons.

The problem with (radio-group) provided by web-server/formlets
is that it always puts the <input>-s on the page in a single
block. It is not possible to put something between them,
or put themselves in a table etc.

And using just (radio) for that purpose makes impossible
forming the group itself: the "name" attributes are all
different, and I see no way to override them in the formlet.

Having the need to organize my radio buttons vertically,
I came up with the following:

(define (vertical-radio-group values #:default (default (void)))
     (lambda (bs)
       (bytes->string/utf-8 (binding:form-value (first bs)))))
     (lambda (n)
         ,@(for/list ((value values))
                   (if (equal? value default) '((checked "1")) '())
                   `((name ,n)
                     (type "radio")
                     (value ,value))))

I am by no means convinced that it is the right way to get
what I want, or the most simple way. Do experienced Racketeers
have any comments?

Best regards,


Posted on the users mailing list.