Skip to content

Commit

Permalink
Fix name and id generation for hidden_field
Browse files Browse the repository at this point in the history
Use the proper rails naming convention for id/name when using bootstrap_form_tag
  • Loading branch information
bikerduweb committed Dec 10, 2016
1 parent defed9f commit e75132c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/bootstrap_form/form_builder.rb
Expand Up @@ -108,6 +108,16 @@ def time_zone_select_with_bootstrap(method, priority_zones = nil, options = {},

bootstrap_method_alias :time_zone_select

def hidden_field_with_bootstrap(method, options = {})
if acts_like_form_tag
options[:id] ||= method.to_s
options[:name] ||= method.to_s
end
hidden_field_without_bootstrap(method, options)
end

bootstrap_method_alias :hidden_field

def check_box_with_bootstrap(name, options = {}, checked_value = "1", unchecked_value = "0", &block)
options = options.symbolize_keys!
options = convert_form_tag_options(name, options) if acts_like_form_tag
Expand Down
5 changes: 5 additions & 0 deletions test/bootstrap_form_test.rb
Expand Up @@ -58,6 +58,11 @@ def setup
assert_equal expected, bootstrap_form_tag(url: '/users') { |f| f.radio_button :misc, 1 }
end

test "bootstrap_form_tag use proper rails naming convention for hidden field" do
expected = %{<form accept-charset=\"UTF-8\" action=\"/users\" method=\"post\" role=\"form\"><div style=\"margin:0;padding:0;display:inline\"><input name=\"utf8\" type=\"hidden\" value=\"&#x2713;\" /></div><input id=\"email\" name=\"email\" type=\"hidden\" value=\"test@yahoo.com\" /></form>}
assert_equal expected, bootstrap_form_tag(url: '/users') { |f| f.hidden_field :email, value: 'test@yahoo.com' }
end

test "errors display correctly and inline_errors are turned off by default when label_errors is true" do
@user.email = nil
@user.valid?
Expand Down

0 comments on commit e75132c

Please sign in to comment.