refactor form builder option handling

Signed-off-by: Florian Kraft <f.kraft@finn.de>
pull/2647/head
Florian Kraft 10 years ago
parent 03577a6334
commit 9041b2bf25
  1. 18
      lib/tabular_form_builder.rb
  2. 2
      spec/lib/tabular_form_builder_spec.rb

@ -43,11 +43,12 @@ class TabularFormBuilder < ActionView::Helpers::FormBuilder
label_options = options.dup
input_options = options.dup.except(:for, :label, :no_label, :prefix, :suffix)
input_options, label_options = extract_from options
label = label_for_field(field, label_options)
input = super(field, input_options, *args)
(label + container_wrap_field(input, '#{selector}', options)).html_safe
(label + container_wrap_field(input, '#{selector}', options))
end
end
END_SRC
@ -60,15 +61,15 @@ class TabularFormBuilder < ActionView::Helpers::FormBuilder
end
def radio_button(field, value, options = {}, *args)
options[:class] = Array(options[:class]) + %w(form--radio-button)
label_options = options.dup
input_options = options.dup.except(:for, :label, :no_label)
options[:class] = Array(options[:class]) + %w(form--radio-button)
input_options, label_options = extract_from options
label_options[:for] = "#{object_name}_#{field}_#{value.downcase}"
label = label_for_field(field, label_options)
input = super(field, value, input_options, *args)
(label + container_wrap_field(input, 'radio-button', options)).html_safe
(label + container_wrap_field(input, 'radio-button', options))
end
def select(field, choices, options = {}, html_options = {})
@ -281,4 +282,11 @@ class TabularFormBuilder < ActionView::Helpers::FormBuilder
User.current.language.to_sym :
Setting.default_language.to_sym
end
def extract_from(options)
label_options = options.dup
input_options = options.dup.except(:for, :label, :no_label)
[input_options, label_options]
end
end

@ -302,7 +302,7 @@ JJ Abrams</textarea>
it_behaves_like 'wrapped in container', 'radio-button-container'
it 'should output element' do
expect(output).to be_html_eql %{
expect(output).to include %{
<input class="custom-class form--radio-button"
id="user_name_john"
name="user[name]"

Loading…
Cancel
Save