Only add required if browser_validations is enabled.

This commit is contained in:
José Valim 2011-12-05 13:11:02 +01:00
parent 2d41fafe9b
commit d245019220
2 changed files with 12 additions and 1 deletions

View File

@ -16,7 +16,10 @@ module SimpleForm
end
def has_required?
required_field?
# We need to check browser_validations because
# some browsers are still checking required even
# if novalidate was given.
required_field? && SimpleForm.browser_validations
end
end
end

View File

@ -249,6 +249,14 @@ class CollectionInputTest < ActionView::TestCase
assert_select 'select[required]'
end
test 'when not using browser validations, input should not generate required html attribute' do
swap SimpleForm, :browser_validations => false do
with_input_for @user, :name, :string
assert_select 'input[type=text].required'
assert_no_select 'input[type=text][required]'
end
end
test 'collection input with select type should not generate required html attribute without blank option' do
with_input_for @user, :name, :select, :include_blank => false, :collection => ['Jose' , 'Carlos']
assert_select 'select.required'