Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #377 from nashby/fix-issue-360

use action prefix in form css class, closes #360
  • Loading branch information...
commit 7c122cb4d8a3f494399b55ff700bc82d9f445605 2 parents c30d4af + e2df674
@rafaelfranca rafaelfranca authored
View
3  lib/simple_form/action_view_extensions/form_helper.rb
@@ -48,7 +48,8 @@ def css_class(record, html_options)
record
else
record = record.last if record.is_a?(Array)
- dom_class(record)
+ action = record.respond_to?(:persisted?) && record.persisted? ? :edit : :new
+ dom_class(record, action)
end
end
View
10 test/action_view_extensions/form_helper_test.rb
@@ -42,9 +42,15 @@ class FormHelperTest < ActionView::TestCase
assert_select 'form.simple_form.user'
end
- test 'simple form should add object class name as css class to form' do
+ test 'simple form should add object class name with new prefix as css class to form if record is not persisted' do
+ @user.new_record!
concat(simple_form_for(@user) do |f| end)
- assert_select 'form.simple_form.user'
+ assert_select 'form.simple_form.new_user'
+ end
+
+ test 'simple form should add edit class prefix as css class to form if record is persisted' do
+ concat(simple_form_for(@user) do |f| end)
+ assert_select 'form.simple_form.edit_user'
end
test 'simple form should not add object class to form if css_class is specified' do
Please sign in to comment.
Something went wrong with that request. Please try again.