Add autofocus attribute support.
This commit is contained in:
parent
965d449fb4
commit
07650728fd
|
@ -30,6 +30,7 @@ module SimpleForm
|
||||||
@input_html_options = html_options_for(:input, input_html_classes).tap do |o|
|
@input_html_options = html_options_for(:input, input_html_classes).tap do |o|
|
||||||
o[:required] = true if has_required?
|
o[:required] = true if has_required?
|
||||||
o[:disabled] = true if disabled?
|
o[:disabled] = true if disabled?
|
||||||
|
o[:autofocus] = true if has_autofocus?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -76,6 +77,10 @@ module SimpleForm
|
||||||
attribute_required?
|
attribute_required?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def has_autofocus?
|
||||||
|
options[:autofocus]
|
||||||
|
end
|
||||||
|
|
||||||
def has_validators?
|
def has_validators?
|
||||||
attribute_name && object.class.respond_to?(:validators_on)
|
attribute_name && object.class.respond_to?(:validators_on)
|
||||||
end
|
end
|
||||||
|
|
|
@ -62,6 +62,41 @@ class InputTest < ActionView::TestCase
|
||||||
assert_select 'select.datetime:not([disabled])'
|
assert_select 'select.datetime:not([disabled])'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test 'input should generate autofocus attribute based on the autofocus option' do
|
||||||
|
with_input_for @user, :name, :string, :autofocus => true
|
||||||
|
assert_select 'input.string[autofocus]'
|
||||||
|
with_input_for @user, :description, :text, :autofocus => true
|
||||||
|
assert_select 'textarea.text[autofocus]'
|
||||||
|
with_input_for @user, :age, :integer, :autofocus => true
|
||||||
|
assert_select 'input.integer[autofocus]'
|
||||||
|
with_input_for @user, :born_at, :date, :autofocus => true
|
||||||
|
assert_select 'select.date[autofocus]'
|
||||||
|
with_input_for @user, :created_at, :datetime, :autofocus => true
|
||||||
|
assert_select 'select.datetime[autofocus]'
|
||||||
|
|
||||||
|
with_input_for @user, :name, :string, :autofocus => false
|
||||||
|
assert_select 'input.string:not([autofocus])'
|
||||||
|
with_input_for @user, :description, :text, :autofocus => false
|
||||||
|
assert_select 'textarea.text:not([autofocus])'
|
||||||
|
with_input_for @user, :age, :integer, :autofocus => false
|
||||||
|
assert_select 'input.integer:not([autofocus])'
|
||||||
|
with_input_for @user, :born_at, :date, :autofocus => false
|
||||||
|
assert_select 'select.date:not([autofocus])'
|
||||||
|
with_input_for @user, :created_at, :datetime, :autofocus => false
|
||||||
|
assert_select 'select.datetime:not([autofocus])'
|
||||||
|
|
||||||
|
with_input_for @user, :name, :string
|
||||||
|
assert_select 'input.string:not([autofocus])'
|
||||||
|
with_input_for @user, :description, :text
|
||||||
|
assert_select 'textarea.text:not([autofocus])'
|
||||||
|
with_input_for @user, :age, :integer
|
||||||
|
assert_select 'input.integer:not([autofocus])'
|
||||||
|
with_input_for @user, :born_at, :date
|
||||||
|
assert_select 'select.date:not([autofocus])'
|
||||||
|
with_input_for @user, :created_at, :datetime
|
||||||
|
assert_select 'select.datetime:not([autofocus])'
|
||||||
|
end
|
||||||
|
|
||||||
test 'input should render components according to an optional :components option' do
|
test 'input should render components according to an optional :components option' do
|
||||||
with_input_for @user, :name, :string, :components => [:input, :label]
|
with_input_for @user, :name, :string, :components => [:input, :label]
|
||||||
assert_select 'input + label'
|
assert_select 'input + label'
|
||||||
|
|
Loading…
Reference in New Issue