Add support for f.actions / f.action in forms. ( issue #1085 ) #1139

Closed
wants to merge 1 commit into
from
@@ -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;
@@ -5,8 +5,8 @@
f.inputs do
f.input :email
end
- 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 %>
@@ -8,8 +8,8 @@
f.input :password
f.input :remember_me, :as => :boolean, :if => false #devise_mapping.rememberable? }
end
- f.buttons do
- f.commit_button "Login"
+ f.actions do
+ f.action :submit, :label => "Login", :button_html => { :value => "Login" }
end
end
%>
@@ -70,8 +70,8 @@ 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.actions do
+ form.action :submit, :label => I18n.t('active_admin.comments.add'), :button_html => { :value => I18n.t('active_admin.comments.add') }
end
end
end
@@ -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] ||= ""
@@ -41,7 +41,7 @@ def default_form_path
def default_form_config
ActiveAdmin::PagePresenter.new do |f|
f.inputs
- f.buttons
+ f.actions
end
end
end
@@ -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
@@ -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]" })
@@ -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
@@ -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|
@@ -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|