[racket] Some more questions about using/composing Formlets

From: J G Cho (gcho at fundingmatters.com)
Date: Thu Dec 29 16:42:14 EST 2011

After tinkering with Formlets a bit, I have some questions for the experts.

1. I am trying to use Formlet with Template to piggy back
on some given CSS/JSs (from Wufoo in this instance),
which means I have to provide lots of #attributes and ((class "left
right large small"))
So, I am forced to do

 (span
  ,{(to-string
     (required
      (text-input #:attributes '((class "field text fn") (size "8") ))))
    . => . first}
  (label "First"))
 (span
  ,{(to-string
     (required
      (text-input #:attributes '((class "field text ln")  (size "14") ))))
    . => . last}
  (label "Last")))

instead of using input-string.

Is there a way to pass in #:attribute to input-string?

2. Another consequence of using Formlets with given CSS/JSs is that
code gets rather long and
polluted with lots of ((class "blah blah blah")) and #:attributes (...)
At the end of the day, it makes me wonder if it's worth the effort
doing it this way
(https://github.com/racketeer/racketeering/blob/master/wufooing/emergency-contact.rkt).

Maybe I am better off with just using templates, any thoughts/advice on this?

3. Say I have a Formlet like this to be used in different places.

(define name-formlet
  (formlet
     (div
        (label "First Name")
        ,{input-string . => . first}
        (label "Last Name")
        ,{input-string . => . last})
     (list first last)))


...some where

(formlet
   (fieldset
      (legend "Guy")
      ,{name-formlet . =+ . guy}
      ,{phone-formlet ...
      ...

... else where

(formlet
   (fieldset
      (legend "Gal")
      ,{name-formlet . =+ . gal}
      ,{phone-formlet ...
      ...

I want the label and input tags to come out without div tag and become
children of fieldset tag so I end up with

<fieldset>
<legend>
<label><input ....
<label><input ....

instead of

<fieldset>
<legend>
<div>
<label><input ....
<label><input ....

Is there a way to do this? It seems I cannot define like this:
(define name-formlet
  (formlet
     (list-that-is-not-tag???
        (label "First Name")
        ,{input-string . => . first}
        (label "Last Name")
        ,{input-string . => . last})
     (list first last)))

or like
(define name-formlet
  (formlet
        ;things, with last one being the bound names...
        (label "First Name")
        ,{input-string . => . first}
        (label "Last Name")
        ,{input-string . => . last}
       (list first last) ))


Regards,

jGc


Posted on the users mailing list.