Ha. Great minds stink alike. I just discovered this little setback
(after adding "id" attributes to about fifty checkboxes -- note to self:
check one before doing them all).
I've been messing with the map but it's messing with me. I can grab the
right node pretty easily, but then I can't seem to add the MetaData.
If you're looking to add an id, you can use checkbox_id:
SHtml.checkbox_id(user.isStupid, user.isStupid = _, Full("isStupid"))
which adds id="isStupid" to the checkbox input.
Chas.
Derek Chen-Becker wrote:
> For a really neat trick, how would I set the ID for a checkbox? The
> SHtml checkbox method returns a NodeSeq. I suppose I could just do a
> "map", but I was wondering if there was a simpler way.
>
> Thanks,
>
> Derek
>
> On Mon, Nov 17, 2008 at 4:54 PM, David Pollak
> <[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>>
> wrote:
>
>
>
> On Mon, Nov 17, 2008 at 3:41 PM, Charles F. Munat <[EMAIL PROTECTED]
> <mailto:[EMAIL PROTECTED]>> wrote:
>
>
> Added:
>
>
> http://liftweb.net/index.php/FAQ#How_do_I_add_attributes_to_form_fields_created_with_SHtml_methods.3F
>
>
> Awesome! Thanks!
>
>
>
> Chas.
>
> Jorge Ortiz wrote:
> > Oops, it might be:
> >
> > SHtml.text(user.name <http://user.name> <http://user.name>,
> user.name <http://user.name> <http://user.name> = _) %
> > ("size" -> "24") %
> > ("maxlength" -> "48") %
> > ("id" -> "user_name") %
> > ("title" -> "Enter your name")
> >
> > One or both of those should work.
> >
> > --j
> >
> > On Mon, Nov 17, 2008 at 12:27 PM, Jorge Ortiz
> <[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>
> > <mailto:[EMAIL PROTECTED]
> <mailto:[EMAIL PROTECTED]>>> wrote:
> >
> > Try:
> >
> > SHtml.text(user.name <http://user.name>
> <http://user.name>, user.name <http://user.name>
> > <http://user.name> = _) %
> > ("size", "24") %
> > ("maxlength", "48") %
> > ("id", "user_name") %
> > ("title", "Enter your name")
> >
> > That should work.
> >
> > --j
> >
> > On Mon, Nov 17, 2008 at 12:21 PM, Charles F. Munat
> <[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>
> > <mailto:[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>>> wrote:
> >
> >
> > I spend a lot of time writing % new
> UnprefixedAttribute(...) to add
> > attributes to SHtml form elements (input, textarea,
> select, etc.).
> >
> > It would be nice if the relevant SHtml methods would
> permit optional
> > extra parameters in the form of tuples where contents
> are name-value
> > pairs that get translated to attributes. I don't
> think this
> > would be a
> > breaking change.
> >
> > In other words, instead of:
> >
> > SHtml.text(user.name <http://user.name>
> <http://user.name>, user.name <http://user.name>
> > <http://user.name> = _) %
> > new UnprefixedAttribute("size", "24",
> > new UnprefixedAttribute("maxlength", "48",
> > new UnprefixedAttribute("id", "user_name",
> > new UnprefixedAttribute("title", "Enter your
> name", Null)
> > )
> > )
> > )
> >
> > I could do:
> >
> > SHtml.text(user.name <http://user.name>
> <http://user.name>, user.name <http://user.name>
> > <http://user.name> = _,
> > ("size", "24"),
> > ("maxlength", "48"),
> > ("id", "user_name"),
> > ("title", "Enter your name")
> > )
> >
> > Which is a hell of a lot cleaner and faster, and I
> don't have to
> > import
> > UnprefixedAttribute and remember the % and the new
> keywords.
> >
> > Or is this already possible and I'm missing it?
> >
> > I have an online survey with 43 questions on 5 pages
> involving
> > more than
> > 150 database fields. The snippet is already over 700
> lines and
> > growing.
> > It's just unmanageable.
> >
> > Another thing: the <label> element is a very
> important part of
> > accessibility to persons with disabilities, but it
> needs a "for"
> > attribute that references the "id" attribute of the input
> > element (or
> > textarea, etc.). The current SHtml output (unlike
> Rails) does not
> > generate an id attribute, so they have to be added by
> hand. Has
> > anyone
> > given any thought to automatically-generated id
> elements on form
> > fields?
> > Better yet, some way to integrate labels?
> >
> > Ideally, I would do something like this:
> >
> > <survey:name label="Your name"/>
> >
> > Or this:
> >
> > <survey:name>Your name</survey:name>
> >
> > and bind would allow me to generate this:
> >
> > <label for="id123">Your name
> > <input type="text" id="id123" value=""
> > name="F1226951216428645000_I0G"/>
> > </label>
> >
> > What do others think? Is this already possible?
> >
> > Chas.
> >
> >
> >
> >
> >
> > >
>
>
>
>
>
> --
> Lift, the simply functional web framework http://liftweb.net
> Collaborative Task Management http://much4.us
> Follow me: http://twitter.com/dpp
> Git some: http://github.com/dpp
>
>
>
>
>
> >
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Lift" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/liftweb?hl=en
-~----------~----~----~----~------~----~------~--~---