1
0
Fork 0
mirror of https://github.com/heartcombo/simple_form.git synced 2022-11-09 12:19:26 -05:00

Adding css classes to form

This commit is contained in:
Carlos Antonio da Silva 2009-12-10 21:31:03 -02:00
parent a3045647df
commit 818414e9bc
2 changed files with 24 additions and 2 deletions

View file

@ -12,10 +12,17 @@ module SimpleForm
module FormHelper
[:form_for, :fields_for, :remote_form_for].each do |helper|
class_eval <<-METHOD, __FILE__, __LINE__
def simple_#{helper}(*args, &block)
def simple_#{helper}(record_or_name_or_array, *args, &block)
options = args.extract_options!
options[:builder] = SimpleForm::FormBuilder
#{helper}(*(args << options), &block)
css_class = case record_or_name_or_array
when String, Symbol then record_or_name_or_array.to_s
when Array then dom_class(record_or_name_or_array.last)
else dom_class(record_or_name_or_array)
end
options[:html] ||= {}
options[:html][:class] = "simple_form \#{css_class} \#{options[:html][:class]}".strip
#{helper}(record_or_name_or_array, *(args << options), &block)
end
METHOD
end

View file

@ -8,6 +8,21 @@ class FormHelperTest < ActionView::TestCase
end
end
test 'simple form should add default class to form' do
simple_form_for :user do |f| end
assert_select 'form.simple_form'
end
test 'simple form should add object name as css class to form when object is not present' do
simple_form_for :user do |f| end
assert_select 'form.simple_form.user'
end
test 'simple form should add object class name as css class to form' do
simple_form_for @user do |f| end
assert_select 'form.simple_form.user'
end
test 'pass options to simple form' do
simple_form_for :user, :url => '/account', :html => { :id => 'my_form' } do |f| end
assert_select 'form#my_form'