Well, the issue for me is that simple_form is not following the same
pattern that rails does when generating a form...
If you do:
form_for User.new do
...
end
that will give you a class "new_user"
and lastly if you do:
form_for User.first do
...
end
that will give you a class "edit_user"... And the most important part
is, you can do:
form_for User.new, :html => {:class => nil} do
...
end
and you will get a form with no class at all. Simple_form's current
functionality, regardless of whether it's a new record or not, will
just give you a class "user". So my objection is to not have control
over the html attributes of my form.
I think a fair compromise would be to replicate rails' form_for class
attribute behavior... That would be something like:
def simple_form_for(record, options={}, &block)
options[:builder] ||= SimpleForm::FormBuilder
options[:html] ||= {}
unless options[:html].key?(:novalidate)
options[:html][:novalidate] = !SimpleForm.browser_validations
end
options[:html][:class] = [SimpleForm.form_class,
css_class(record, html_options)].compact.join(" ")
with_custom_field_error_proc do
form_for(record, options, &block)
end
end
def css_class(record, html_options)
record = record.last if record.is_a?(Array)
if html_options.has_key?(:class)
html_options[:class]
else
dom_class(record, (record.new_record? ? :new : :edit))
end
end
So this way, if someone uses an array like,
[:person, :posts, @comment], it will still function properly and give
a new_comment or edit_comment class...
The only behavior this is lacking is if a user passes in a string..
simple_form_for "User" do... But in this case, I think if they need a
specific user class, they can just pass it in as the css option...
What do you guys think? If you like this I will be happy to package
it up on a new branch and write some tests and do another pull
request.
-patrick
On Jul 25, 6:16 pm, Carlos Antonio <
carlosantoniodasi...@gmail.com>
wrote:
> I'm not completely sure if that should be handled by SimpleForm. We're used to create a wrapper with an id (or sometimes another class) such as a div#flash or div.flash and put the specific messages (notice, alert) inside it. This way I can style them only under the #flash context, avoiding such issues with global classes, solving this.
>
> This way you wouldn't neither need to change your css class names, nor the way SimpleForm handles it. This is just an idea that might help you solving the issue in an easy way and would avoid more changes in SimpleForm, but if you do think it'd be better to change SimpleForm code for that, pls go ahead =). Thanks.
>
> --
> At.
> Carlos A. da Silva
>
>
>
>
>
>
>
> On Monday, July 25, 2011 at 8:54 PM, Rafael Mendonça França wrote:
> > Please, go ahead an send us a pull request. We will be happy to help you with this issue.
>
> > --
> > Rafael Mendonça França
> > Software developer at Plataformatec
> >
http://twitter.com/rafaelfranca
> >
https://github.com/rafaelfranca
> > Sent with Sparrow (
http://www.sparrowmailapp.com)