Do not remove HTML attributes if components are not present
Closes #1096
This commit is contained in:
parent
ee62c0f37a
commit
6c28bf4833
|
@ -131,14 +131,15 @@ module SimpleForm
|
||||||
# name="user[name]" type="text" value="Carlos" />
|
# name="user[name]" type="text" value="Carlos" />
|
||||||
#
|
#
|
||||||
def input_field(attribute_name, options = {})
|
def input_field(attribute_name, options = {})
|
||||||
|
components = (wrapper.components.map(&:namespace) & ATTRIBUTE_COMPONENTS)
|
||||||
|
|
||||||
options = options.dup
|
options = options.dup
|
||||||
options[:input_html] = options.except(:as, :boolean_style, :collection, :label_method, :value_method, *ATTRIBUTE_COMPONENTS)
|
options[:input_html] = options.except(:as, :boolean_style, :collection, :label_method, :value_method, *components)
|
||||||
options = @defaults.deep_dup.deep_merge(options) if @defaults
|
options = @defaults.deep_dup.deep_merge(options) if @defaults
|
||||||
|
|
||||||
input = find_input(attribute_name, options)
|
input = find_input(attribute_name, options)
|
||||||
wrapper = find_wrapper(input.input_type, options)
|
wrapper = find_wrapper(input.input_type, options)
|
||||||
components = (wrapper.components.map(&:namespace) & ATTRIBUTE_COMPONENTS) + [:input]
|
components = components.concat([:input]).map { |component| SimpleForm::Wrappers::Leaf.new(component) }
|
||||||
components = components.map { |component| SimpleForm::Wrappers::Leaf.new(component) }
|
|
||||||
|
|
||||||
SimpleForm::Wrappers::Root.new(components, wrapper.options.merge(wrapper: false)).render input
|
SimpleForm::Wrappers::Root.new(components, wrapper.options.merge(wrapper: false)).render input
|
||||||
end
|
end
|
||||||
|
|
|
@ -146,4 +146,44 @@ class InputFieldTest < ActionView::TestCase
|
||||||
|
|
||||||
assert_no_select 'input.boolean[boolean_style]'
|
assert_no_select 'input.boolean[boolean_style]'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test 'build input_field without pattern component use the pattern string' do
|
||||||
|
swap_wrapper :default, self.custom_wrapper_with_html5_components do
|
||||||
|
with_concat_form_for(@user) do |f|
|
||||||
|
f.input_field :name, pattern: '\w+'
|
||||||
|
end
|
||||||
|
|
||||||
|
assert_select 'input[pattern="\w+"]'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
test 'build input_field without placeholder component use the placeholder string' do
|
||||||
|
swap_wrapper :default, self.custom_wrapper_with_html5_components do
|
||||||
|
with_concat_form_for(@user) do |f|
|
||||||
|
f.input_field :name, placeholder: 'Placeholder'
|
||||||
|
end
|
||||||
|
|
||||||
|
assert_select 'input[placeholder="Placeholder"]'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
test 'build input_field without maxlength component use the maxlength string' do
|
||||||
|
swap_wrapper :default, self.custom_wrapper_with_html5_components do
|
||||||
|
with_concat_form_for(@user) do |f|
|
||||||
|
f.input_field :name, maxlength: 5
|
||||||
|
end
|
||||||
|
|
||||||
|
assert_select 'input[maxlength="5"]'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
test 'build input_field without readonly component use the readonly string' do
|
||||||
|
swap_wrapper :default, self.custom_wrapper_with_html5_components do
|
||||||
|
with_concat_form_for(@user) do |f|
|
||||||
|
f.input_field :name, readonly: true
|
||||||
|
end
|
||||||
|
|
||||||
|
assert_select 'input[readonly="readonly"]'
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -178,6 +178,12 @@ module MiscHelpers
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def custom_wrapper_with_html5_components
|
||||||
|
SimpleForm.build tag: :span, class: 'custom_wrapper' do |b|
|
||||||
|
b.use :label_text
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def custom_form_for(object, *args, &block)
|
def custom_form_for(object, *args, &block)
|
||||||
simple_form_for(object, *args, { builder: CustomFormBuilder }, &block)
|
simple_form_for(object, *args, { builder: CustomFormBuilder }, &block)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue