Skip to content

Commit

Permalink
Merge pull request marcometz#1 from jazzgumpy/master
Browse files Browse the repository at this point in the history
beseitigt die deprecation warnings für formtastic
  • Loading branch information
marcometz committed Mar 28, 2012
2 parents 5932d53 + 40fd941 commit 7fd46d1
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 11 deletions.
4 changes: 2 additions & 2 deletions app/assets/stylesheets/active_admin/_forms.css.scss
Expand Up @@ -165,12 +165,12 @@ form {

}

.buttons {
.buttons, .actions {
margin-top: 15px;
input[type=submit] { margin-right: 10px; }
}

fieldset.buttons li {
fieldset.buttons li, fieldset.actions li {
float:left;
padding: 0;

Expand Down
6 changes: 4 additions & 2 deletions app/views/active_admin/devise/passwords/new.html.erb
Expand Up @@ -5,8 +5,10 @@
f.inputs do
f.input :email
end
f.buttons do
f.commit_button "Reset My Password"
# f.buttons do
# f.commit_button "Reset My Password"
f.actions do
f.action :submit, :label => "Reset My Password", :button_html => { :value => "Reset My Password" }
end
end %>
Expand Down
6 changes: 4 additions & 2 deletions app/views/active_admin/devise/sessions/new.html.erb
Expand Up @@ -8,8 +8,10 @@
f.input :password
f.input :remember_me, :as => :boolean, :if => false #devise_mapping.rememberable? }
end
f.buttons do
f.commit_button "Login"
# f.buttons do
# f.commit_button "Login"
f.actions do
f.action :submit, :label => "Login", :button_html => { :value => "Login" }
end
end
%>
Expand Down
6 changes: 4 additions & 2 deletions lib/active_admin/comments/views/active_admin_comments.rb
Expand Up @@ -70,8 +70,10 @@ def build_comment_form
form.input :resource_id, :value => @record.id, :as => :hidden
form.input :body, :input_html => {:size => "80x8"}, :label => false
end
form.buttons do
form.commit_button I18n.t('active_admin.comments.add')
#form.buttons do
form.actions do
#form.commit_button I18n.t('active_admin.comments.add')
form.action :submit, :label => I18n.t('active_admin.comments.add'), :button_html => { :value => I18n.t('active_admin.comments.add') }
end
end
end
Expand Down
17 changes: 17 additions & 0 deletions lib/active_admin/form_builder.rb
Expand Up @@ -48,6 +48,23 @@ def commit_button_with_cancel_link
content << cancel_link
end

def actions(*args, &block)
content = with_new_form_buffer do
block_given? ? super : super { commit_action_with_cancel_link }
end
form_buffers.last << content.html_safe
end

def action(*args)
content = with_new_form_buffer { super }
form_buffers.last << content.html_safe
end

def commit_action_with_cancel_link
content = action(:submit)
content << cancel_link
end

def has_many(association, options = {}, &block)
options = { :for => association }.merge(options)
options[:class] ||= ""
Expand Down
3 changes: 2 additions & 1 deletion lib/active_admin/views/pages/form.rb
Expand Up @@ -41,7 +41,8 @@ def default_form_path
def default_form_config
ActiveAdmin::PagePresenter.new do |f|
f.inputs
f.buttons
#f.buttons
f.actions
end
end
end
Expand Down
78 changes: 76 additions & 2 deletions spec/unit/form_builder_spec.rb
Expand Up @@ -36,7 +36,7 @@ def build_form(options = {}, &block)
active_admin_form_for Post.new, options, &block
end

context "in general" do
context "in general with buttons" do
let :body do
build_form do |f|
f.inputs do
Expand All @@ -50,6 +50,38 @@ def build_form(options = {}, &block)
end
end

it "should generate a text input" do
body.should have_tag("input", :attributes => { :type => "text",
:name => "post[title]" })
end
it "should generate a textarea" do
body.should have_tag("textarea", :attributes => { :name => "post[body]" })
end
it "should only generate the form once" do
body.scan(/Title/).size.should == 1
end
it "should generate buttons" do
body.should have_tag("input", :attributes => { :type => "submit",
:value => "Submit Me" })
body.should have_tag("input", :attributes => { :type => "submit",
:value => "Another Button" })
end
end

context "in general with actions" do
let :body do
build_form do |f|
f.inputs do
f.input :title
f.input :body
end
f.actions do
f.action :submit, :button_html => { :value => "Submit Me" }
f.action :submit, :button_html => { :value => "Another Button" }
end
end
end

it "should generate a text input" do
body.should have_tag("input", :attributes => { :type => "text",
:name => "post[title]" })
Expand Down Expand Up @@ -79,7 +111,7 @@ def build_form(options = {}, &block)
end
end

describe "passing in options" do
describe "passing in options with buttons" do
let :body do
build_form :html => { :multipart => true } do |f|
f.inputs :title
Expand All @@ -91,6 +123,19 @@ def build_form(options = {}, &block)
end
end

describe "passing in options with actions" do
let :body do
build_form :html => { :multipart => true } do |f|
f.inputs :title
f.actions
end
end
it "should pass the options on to the form" do
body.should have_tag("form", :attributes => { :enctype => "multipart/form-data" })
end
end


context "with buttons" do
it "should generate the form once" do
body = build_form do |f|
Expand Down Expand Up @@ -121,6 +166,35 @@ def build_form(options = {}, &block)

end

context "with actons" do
it "should generate the form once" do
body = build_form do |f|
f.inputs do
f.input :title
end
f.actions
end
body.scan(/id=\"post_title\"/).size.should == 1
end
it "should generate one button and a cancel link" do
body = build_form do |f|
f.actions
end
body.scan(/type=\"submit\"/).size.should == 1
body.scan(/class=\"cancel\"/).size.should == 1
end
it "should generate multiple actions" do
body = build_form do |f|
f.actions do
f.action :submit, :label => "Create & Continue"
f.action :submit, :label => "Create & Edit"
end
end
body.scan(/type=\"submit\"/).size.should == 2
body.scan(/class=\"cancel\"/).size.should == 0
end
end

context "without passing a block to inputs" do
let :body do
build_form do |f|
Expand Down

0 comments on commit 7fd46d1

Please sign in to comment.