Julio
Julio

Reputation: 1943

Formtastic set class in all forms

There's a way to add a class attribute in all the forms using formtastic?

I don't want to edit every form using something like this:

<% semantic_form_for @meetingsearch, :html => { :class => "my_class", :id => "my_id" } do |f| %>

Upvotes: 0

Views: 303

Answers (2)

Jari Jokinen
Jari Jokinen

Reputation: 770

You can set the default form class in the initializer:

Formtastic::Helpers::FormHelper.default_form_class = "my_class"

Upvotes: 4

Sukima
Sukima

Reputation: 10074

I do not believe there is a built-in way to do this. My recommendation is to create a new definition for semantic_form_for in which you add the :class to the original semantic_form_for.

Overriding a method, or making a new method, or changing the original source all seems more effort then a simple grep and replace of the views. A good text editor should easily search the files and add a :class declaration to all the semantic_form_for lines.

I know it isn't a DRY as you were hoping for an answer but I don't think there is any easy way to do this as you expected.

On a side note you can do this for inputs. I made several custom inputs which were nothing more then the stock inputs with a :class attribute added. I don't thing there is the same kind of setup for the form itself though.

Upvotes: 0

Related Questions