From 795691aced344ace67a885c42ce96c9d3cbb1c8c Mon Sep 17 00:00:00 2001 From: Vinicius Baggio Date: Thu, 26 May 2011 14:40:17 -0300 Subject: [PATCH] Do not use required='required' when browser validations are turned off --- lib/simple_form/inputs/base.rb | 2 +- test/inputs_test.rb | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/simple_form/inputs/base.rb b/lib/simple_form/inputs/base.rb index e511e626..1474d5a1 100644 --- a/lib/simple_form/inputs/base.rb +++ b/lib/simple_form/inputs/base.rb @@ -74,7 +74,7 @@ module SimpleForm # Whether this input is valid for HTML 5 required attribute. def has_required? - attribute_required? && SimpleForm.html5 + attribute_required? && SimpleForm.html5 && SimpleForm.browser_validations end def has_autofocus? diff --git a/test/inputs_test.rb b/test/inputs_test.rb index e2413123..88ec56e9 100644 --- a/test/inputs_test.rb +++ b/test/inputs_test.rb @@ -780,6 +780,14 @@ class InputTest < ActionView::TestCase end 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 invalid required html attribute' do with_input_for @user, :name, :select, :collection => ['Jose' , 'Carlos'] assert_select 'select.required'