Skip to content

add label_text method to single wrapper #617

Merged
merged 3 commits into from Apr 2, 2014
View
3 lib/simple_form/components/labels.rb
@@ -30,7 +30,8 @@ def label
end
def label_text
- SimpleForm.label_text.call(raw_label_text, required_label_text).strip.html_safe
+ label_text = options[:label_text] || SimpleForm.label_text
+ label_text.call(raw_label_text, required_label_text).strip.html_safe
end
def label_target
View
10 test/form_builder/label_test.rb
@@ -68,4 +68,14 @@ def with_label_for(object, *args, &block)
assert_select 'label.integer[for=user_age]', "Age:"
end
end
+
+ test 'configuration allow set label text for wrappers' do
+ swap_wrapper :default, self.custom_wrapper_with_label_text do
+ with_concat_form_for(@user) do |f|
+ concat f.input :age
+ end
+ assert_select "label.integer[for=user_age]", "**Age**"
+ end
+ end
+
end
View
6 test/support/misc_helpers.rb
@@ -84,6 +84,12 @@ def custom_wrapper_with_label_html_option
end
end
+ def custom_wrapper_with_label_text
+ SimpleForm.build :label_text => lambda { |label, required| "**#{label}**" } do |b|
+ b.use :label_input
+ end
+ end
+
def custom_form_for(object, *args, &block)
simple_form_for(object, *(args << { :builder => CustomFormBuilder }), &block)
end
Something went wrong with that request. Please try again.