[racket] playing with formlets: vertical radio buttons

From: Jay McCarthy (jay.mccarthy at gmail.com)
Date: Tue Dec 10 11:21:59 EST 2013

Hi Dmitry,

Your version looks like it would probably. I think that I would do is
process the result of the radio-group formlet though.

Like this:

#lang racket
(require web-server/formlets)

(define f
  (formlet ,(=> (radio-group (list 1 2 3 4) #:display number->string)
                rg)
           rg))
(define fxes (formlet-display f))
(define xe
  `(table ,@(for/list ([f (in-list fxes)])
              `(tr (td ,f)))))

(module+ test
  f
  fxes
  xe)



On Mon, Dec 9, 2013 at 12:02 PM, Dmitry Pavlov <dpavlov at ipa.nw.ru> wrote:
> Hello,
>
> 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)))
>   (cross
>    (pure
>     (lambda (bs)
>       (bytes->string/utf-8 (binding:form-value (first bs)))))
>    (make-input*
>     (lambda (n)
>       `(table
>         ,@(for/list ((value values))
>             `(tr
>               (td
>                (input
>                 ,(append
>                   (if (equal? value default) '((checked "1")) '())
>                   `((name ,n)
>                     (type "radio")
>                     (value ,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,
>
> Dmitry
>
> ____________________
>  Racket Users list:
>  http://lists.racket-lang.org/users



-- 
Jay McCarthy <jay at cs.byu.edu>
Assistant Professor / Brigham Young University
http://faculty.cs.byu.edu/~jay

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

Posted on the users mailing list.