Merge pull request #43886 from seanpdoyle/form-builder-button-method-name-id
Generate `[id]` for `FormBuilder#button` called with method name
This commit is contained in:
commit
2a55e3432c
|
@ -2587,7 +2587,7 @@ module ActionView
|
|||
# # => <button name='button' type='submit'>Create post</button>
|
||||
#
|
||||
# button(:draft, value: true)
|
||||
# # => <button name="post[draft]" value="true" type="submit">Create post</button>
|
||||
# # => <button id="post_draft" name="post[draft]" value="true" type="submit">Create post</button>
|
||||
#
|
||||
# button do
|
||||
# content_tag(:strong, 'Ask me!')
|
||||
|
@ -2606,7 +2606,7 @@ module ActionView
|
|||
# button(:draft, value: true) do
|
||||
# content_tag(:strong, "Save as draft")
|
||||
# end
|
||||
# # => <button name="post[draft]" value="true" type="submit">
|
||||
# # => <button id="post_draft" name="post[draft]" value="true" type="submit">
|
||||
# # <strong>Save as draft</strong>
|
||||
# # </button>
|
||||
#
|
||||
|
@ -2615,7 +2615,7 @@ module ActionView
|
|||
when Hash
|
||||
value, options = nil, value
|
||||
when Symbol
|
||||
value, options[:name] = nil, field_name(value)
|
||||
value, options = nil, { name: field_name(value), id: field_id(value) }.merge!(options.to_h)
|
||||
end
|
||||
value ||= submit_default_value
|
||||
|
||||
|
|
|
@ -2607,7 +2607,19 @@ class FormHelperTest < ActionView::TestCase
|
|||
end
|
||||
|
||||
expected = whole_form("/posts/123", "edit_post_123", "edit_post", method: "patch") do
|
||||
%(<button type="submit" name="post[secret]" value="true">Update Post</button>)
|
||||
%(<button type="submit" id="post_secret" name="post[secret]" value="true">Update Post</button>)
|
||||
end
|
||||
|
||||
assert_dom_equal expected, output_buffer
|
||||
end
|
||||
|
||||
def test_button_with_method_name_and_attributes
|
||||
form_for(@post) do |f|
|
||||
concat f.button(:secret, value: true, id: "not_generated", name: "post[not_generated]")
|
||||
end
|
||||
|
||||
expected = whole_form("/posts/123", "edit_post_123", "edit_post", method: "patch") do
|
||||
%(<button type="submit" id="not_generated" name="post[not_generated]" value="true">Update Post</button>)
|
||||
end
|
||||
|
||||
assert_dom_equal expected, output_buffer
|
||||
|
@ -2619,7 +2631,7 @@ class FormHelperTest < ActionView::TestCase
|
|||
end
|
||||
|
||||
expected = whole_form("/posts/123", "edit_post_123", "edit_post", method: "patch") do
|
||||
%(<button type="submit" name="post[secret]" value="true">Update secret Post</button>)
|
||||
%(<button type="submit" id="post_secret" name="post[secret]" value="true">Update secret Post</button>)
|
||||
end
|
||||
|
||||
assert_dom_equal expected, output_buffer
|
||||
|
|
Loading…
Reference in New Issue