Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #46 from sshaw/rails

Added id option for uneditable_input, minor fixes for form_tag_helpers
  • Loading branch information...
commit c1d51d1cbfcbdbcf92b706823cd4557ac8c8b09c 2 parents b3f94da + 6be8b42
@sethvargo authored
View
4 lib/bootstrap_forms/form_builder.rb
@@ -119,7 +119,9 @@ def uneditable_input(name, *args)
control_group_div do
label_field + input_div do
extras do
- content_tag(:span, :class => 'uneditable-input') do
+ options = { :class => 'uneditable-input' }
+ options[:id] = @field_options[:id] if @field_options[:id]
+ content_tag(:span, options) do
@field_options[:value] || object.send(@name.to_sym)
end
end
View
11 lib/bootstrap_forms/helpers/form_tag_helper.rb
@@ -7,17 +7,16 @@ def bootstrap_form_tag(url_for_options = {}, options = {}, &block)
form_tag(url_for_options, options, &block)
end
- %w(button_tag check_box_tag email_field_tag field_set_tag file_field_tag image_submit_tag label_tag number_field_tag password_field_tag phone_field_tag radio_button_tag range_field_tag search_field_tag select_tag telephone_field_tag text_area_tag text_field_tag url_field_tag utf8_enforcer_tag).each do |method_name|
+ %w(check_box_tag email_field_tag file_field_tag image_submit_tag number_field_tag password_field_tag phone_field_tag radio_button_tag range_field_tag search_field_tag select_tag telephone_field_tag text_area_tag text_field_tag url_field_tag).each do |method_name|
# prefix each method with bootstrap_*
define_method("bootstrap_#{method_name}") do |name, *args|
- value = args.shift
@name = name
@field_options = args.extract_options!
@args = args
control_group_div do
label_field + input_div do
- extras { send(method_name.to_sym, name, value, *(@args << @field_options)) }
+ extras { send(method_name.to_sym, name, *(@args << @field_options)) }
end
end
end
@@ -27,12 +26,12 @@ def uneditable_input_tag(name, *args)
@name = name
@field_options = args.extract_options!
@args = args
-
+
control_group_div do
label_field + input_div do
extras do
content_tag(:span, :class => 'uneditable-input') do
- @field_options[:value] || object.send(@name.to_sym)
+ @field_options[:value]
end
end
end
@@ -73,4 +72,4 @@ def bootstrap_actions(&block)
end
end
end
-end
+end
View
12 spec/lib/bootstrap_forms/form_builder_spec.rb
@@ -53,6 +53,16 @@
end
end
+ describe "uneditable_input" do
+ it "generates wrapped input" do
+ @builder.uneditable_input("name").should == "<div class=\"control-group\"><label class=\"control-label\" for=\"item_name\">Name</label><div class=\"controls\"><span class=\"uneditable-input\"></span></div></div>"
+ end
+
+ it "allows for an id" do
+ @builder.uneditable_input("name", :id => "myid").should match /<span.*id="myid"/
+ end
+ end
+
describe "check_box" do
it "generates wrapped input" do
@builder.check_box("name").should == "<div class=\"control-group\"><div class=\"controls\"><label class=\"checkbox\" for=\"item_name\"><input name=\"item[name]\" type=\"hidden\" value=\"0\" /><input id=\"item_name\" name=\"item[name]\" type=\"checkbox\" value=\"1\" />Name</label></div></div>"
@@ -112,7 +122,7 @@
end
it "has an input of type: #{type}" do
- @result.should match /<input.*type=["#{type}"]/
+ @result.should match /<input.*type="#{type}"/
end
end # result
View
2  spec/spec_helper.rb
@@ -19,4 +19,4 @@
config.filter_run :focus
end
-Rails.backtrace_cleaner.remove_silencers!
+Rails.backtrace_cleaner.remove_silencers!
Please sign in to comment.
Something went wrong with that request. Please try again.