labeled form tag helpers

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

labeled form tag helpers

Rick Olson
I've been digging the new form block methods form_for and
form_remote_for.  I submitted a patch #3268 [1] that adds label
helpers to the mix:

<%= label_tag 'post_title', 'Title' %>
<%= label_for 'post', 'title' %>
<% fields_for :post, @post do |f| -%>
  <%= f.label_for :title %>
<% end -%>

This sets the for="" attribute to point to the input tag automatically.

Ulysses suggested I take it a step further, and allow you to subclass
FormBuilder for your own purposes.  I made a simple LabeledFormBuilder
that formats your fields like so:

<p><label for=""><br /><input ... /></p>

using:

<% labeled_form_for :foo, @foo do |f| %>
  <%= f.text_field :bar %>
<% end -%>

Having thought about it some more after submitting the final diff, I
think this labeled_form_for stuff should be extracted to a plugin to
show how to write your own FormBuilders.  Who knows, it could be the
start of an admin scaffolding plugin?

Thoughts?

1. http://dev.rubyonrails.org/ticket/3268

--
rick
http://techno-weenie.net
_______________________________________________
Rails-core mailing list
[hidden email]
http://lists.rubyonrails.org/mailman/listinfo/rails-core
Reply | Threaded
Open this post in threaded view
|

Re: labeled form tag helpers

Michael Koziarski
This is really nice Rick.

> <p><label for=""><br /><input ... /></p>

omg wtf, That's not semantic!!!  What I'm trying to get at is that
customisable markup may be a good idea.   Though it also sounds like a
pain in the ass.  After triaging all those Inflector tickets, I'm
terrified of anything which smells like a ticket storm ;)


> Having thought about it some more after submitting the final diff, I
> think this labeled_form_for stuff should be extracted to a plugin to
> show how to write your own FormBuilders.  Who knows, it could be the
> start of an admin scaffolding plugin?

I'd personally *love* to see this as a plugin, as it'll be a great way
to demonstrate customising 'the guts' of rails.   Then perhaps after
some people have used it we'll have a good idea of what does and
doesn't fit as part of the core framework.

--
Cheers

Koz
_______________________________________________
Rails-core mailing list
[hidden email]
http://lists.rubyonrails.org/mailman/listinfo/rails-core
Reply | Threaded
Open this post in threaded view
|

Re: labeled form tag helpers

Manfred Stienstra
In reply to this post by Rick Olson

On Dec 18, 2005, at 9:28 PM, Rick Olson wrote:

> Ulysses suggested I take it a step further, and allow you to subclass
> FormBuilder for your own purposes.  I made a simple LabeledFormBuilder
> that formats your fields like so:
>
> <p><label for=""><br /><input ... /></p>

I don't really like the <br /> and the <p> in the html. I suggest to  
either insert a div around the label or let people style it.

> using:
>
> <% labeled_form_for :foo, @foo do |f| %>
>   <%= f.text_field :bar %>
> <% end -%>
>
> Having thought about it some more after submitting the final diff, I
> think this labeled_form_for stuff should be extracted to a plugin to
> show how to write your own FormBuilders.  Who knows, it could be the
> start of an admin scaffolding plugin?

I generally don't use scaffolding, but I would like to see a  
text_field_with_label helper I guess.

Manfred
_______________________________________________
Rails-core mailing list
[hidden email]
http://lists.rubyonrails.org/mailman/listinfo/rails-core
Reply | Threaded
Open this post in threaded view
|

Re: labeled form tag helpers

Rick Olson
Okay, I spent the ten minutes getting a plugin.  There are a few
changes I needed to get #labeled_form_for to let me change which
FormBuilder class to use.

http://dev.rubyonrails.org/attachment/ticket/3268/form_for.diff

The plugin is located here:
http://techno-weenie.net/svn/projects/plugins/labeled_form_helper/

You'll notice I kept my non-semantic, line break riddled
LabeledFormBuilder in there.  I really thing this depends on the
project and your own opinions on form structure.  Some like tables,
definitiion lists, divs, etc.  At any rate, with that small patch
applied and a few lines, you too can create your own
application-specific FormBuilder class.

--
rick
http://techno-weenie.net
_______________________________________________
Rails-core mailing list
[hidden email]
http://lists.rubyonrails.org/mailman/listinfo/rails-core