[racket] playing with formlets: vertical radio buttons
Jay,
Thanks, your code is more preferable to me as it uses
less of Racket's formlets library internals.
How do I use your "xe" expression if I want to build
a formlet that includes the vertical radio button formlet
plus something else?
For example, if I used the ordinary radio-group formlet,
I would write
(define my-formlet
(formlet
(div "Select:" ,{(radio-group '("A" "B")) . => . rg}
"Input:" ,{input-string . => . text})
(list rg text)))
What do I put instead the (radio-group) in that case?
Sorry for possibly dumb question, I just started to learn
web programming in Racket.
Regards,
Dmitry
On 12/10/2013 08:21 PM, Jay McCarthy wrote:
> 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
>
>
>