[racket] formlets with radio button & checkbox example?
Shad,
thanks for your code!
I'd prefer to have the "name" attribute auto-generated though, as in the other provided formlets, so I'll try taking the multiselect as an example first...
But anyway, thanks for sharing!
Sigrid
Am 29.12.2011 um 08:59 schrieb Shad Gregory:
> Sigrid,
>
> Here's something that worked for me:
>
> (define (radio-group values name)
> (make-input*
> (lambda (n)
> `(div
> ,@(for/list ((value values))
> (list 'div
> (list 'input
> (list
> (list 'name name)
> (list 'type "radio")
> (list 'value (bytes->string/utf-8 value))))
> (bytes->string/utf-8 value)))))))
>
>
> (define radio-button-formlet
> (formlet
> (div
> ,{(default #"default" (radio-group (list #"Chocolate" #"Vanilla" #"Strawberry") "flavor")) . => . ci} )
> (list ci)))
>
> Hope this helps,
>
> Shad
>
> On 12/27/2011 3:20 PM, keydana at gmx.de wrote:
>
>> Jay,
>>
>> many thanks for the answer, that already helps a lot!
>>
>> Just one thing - the generated html does not have a "value" attribute, but instead uses a different "name" for every radio button - how can I get the radio buttons identified as a group by the browser, such that only one button can be selected?
>>
>> In fact, looking at the generated html as well as the input given to formlet-process, I do not see where the "value" passed to the radio constructor is used?
>>
>> Thanks again,
>> Sigrid
>>
>>
>>
>>
>>
>> Am 26.12.2011 um 22:28 schrieb Jay McCarthy:
>>
>>> Here is a short example:
>>>
>>> #lang racket
>>> (require racket/promise
>>> web-server/http/request-structs
>>> web-server/formlets
>>> net/url)
>>>
>>> (define some-formlet
>>> (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")
>>> empty
>>> (delay bs)
>>> #f
>>> "host"
>>> 8943
>>> "client")))
>>>
>>> (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.
>>>
>>> Jay
>>>
>>> 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
>>> http://faculty.cs.byu.edu/~jay
>>>
>>> "The glory of God is Intelligence" - D&C 93
>>
>> ____________________
>> Racket Users list:
>> http://lists.racket-lang.org/users
>>
>