From d2450192207faf016a9a3be129f18fb593d8f5f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Mon, 5 Dec 2011 13:11:02 +0100 Subject: [PATCH] Only add required if browser_validations is enabled. --- lib/simple_form/components/html5.rb | 5 ++++- test/inputs/collection_input_test.rb | 8 ++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/simple_form/components/html5.rb b/lib/simple_form/components/html5.rb index 3adba41e..e0e5ea8f 100644 --- a/lib/simple_form/components/html5.rb +++ b/lib/simple_form/components/html5.rb @@ -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 diff --git a/test/inputs/collection_input_test.rb b/test/inputs/collection_input_test.rb index 40990044..b43db5ea 100644 --- a/test/inputs/collection_input_test.rb +++ b/test/inputs/collection_input_test.rb @@ -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'