From 1c9a9251e59026dae01f257329cb7f335b248b79 Mon Sep 17 00:00:00 2001 From: Cameron Cundiff Date: Sun, 7 Apr 2013 13:52:56 -0400 Subject: [PATCH 1/8] Test aria-required on checkbox collection input [#780] --- test/inputs/collection_check_boxes_input_test.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/inputs/collection_check_boxes_input_test.rb b/test/inputs/collection_check_boxes_input_test.rb index 3fc6a424..ab23bc3c 100644 --- a/test/inputs/collection_check_boxes_input_test.rb +++ b/test/inputs/collection_check_boxes_input_test.rb @@ -23,6 +23,12 @@ class CollectionCheckBoxesInputTest < ActionView::TestCase assert_no_select 'input[required]' end + test 'collection input with check_boxes type should not generate aria-required html attribute' do + with_input_for @user, :name, :check_boxes, collection: ['Jose' , 'Carlos'] + assert_select 'input.required' + assert_no_select 'input[aria-required]' + end + test 'input should do automatic collection translation for check_box types using defaults key' do store_translations(:en, simple_form: { options: { defaults: { gender: { male: 'Male', female: 'Female'} From a15b4700ffd4ac8c4a8a1f558acbfc1821a428af Mon Sep 17 00:00:00 2001 From: Cameron Cundiff Date: Sun, 7 Apr 2013 13:54:45 -0400 Subject: [PATCH 2/8] Test aria-required on collection radio button input. [#780] --- test/inputs/collection_radio_buttons_input_test.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/inputs/collection_radio_buttons_input_test.rb b/test/inputs/collection_radio_buttons_input_test.rb index 745858a2..1d77bb1a 100644 --- a/test/inputs/collection_radio_buttons_input_test.rb +++ b/test/inputs/collection_radio_buttons_input_test.rb @@ -140,6 +140,12 @@ class CollectionRadioButtonsInputTest < ActionView::TestCase assert_select 'input[type=radio][required]' end + test 'collection input with radio type should generate aria-required html attribute' do + with_input_for @user, :name, :radio_buttons, collection: ['Jose' , 'Carlos'] + assert_select 'input[type=radio].required' + assert_select 'input[type=radio][aria-required=true]' + end + test 'input radio does not wrap the collection by default' do with_input_for @user, :active, :radio_buttons From 52f52660d9b3028eff46dadd5c476dd20f4b6fc6 Mon Sep 17 00:00:00 2001 From: Cameron Cundiff Date: Sun, 7 Apr 2013 13:57:07 -0400 Subject: [PATCH 3/8] Test aria-required on collection select input. [#780] --- test/inputs/collection_select_input_test.rb | 25 +++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/test/inputs/collection_select_input_test.rb b/test/inputs/collection_select_input_test.rb index c102696e..56968420 100644 --- a/test/inputs/collection_select_input_test.rb +++ b/test/inputs/collection_select_input_test.rb @@ -176,6 +176,7 @@ class CollectionSelectInputTest < ActionView::TestCase with_input_for @user, :name, :select, include_blank: false, collection: ['Jose' , 'Carlos'] assert_select 'select.required' assert_no_select 'select[required]' + assert_no_select 'select[aria-required=true]' end test 'collection input with select type with multiple attribute should generate required html attribute without blank option' do @@ -190,6 +191,30 @@ class CollectionSelectInputTest < ActionView::TestCase assert_select 'select[required]' end + test 'with a blank option, a collection input of type select has an aria-required html attribute' do + with_input_for @user, :name, :select, include_blank: true, collection: ['Jose' , 'Carlos'] + assert_select 'select.required' + assert_select 'select[aria-required=true]' + end + + test 'without a blank option, a collection input of type select does not have an aria-required html attribute' do + with_input_for @user, :name, :select, include_blank: false, collection: ['Jose' , 'Carlos'] + assert_select 'select.required' + assert_no_select 'select[aria-required]' + end + + test 'without a blank option and with a multiple option, a collection input of type select has an aria-required html attribute' do + with_input_for @user, :name, :select, include_blank: false, input_html: {multiple: true}, collection: ['Jose' , 'Carlos'] + assert_select 'select.required' + assert_select 'select[aria-required=true]' + end + + test 'with a blank option and a multiple option, a collection input of type select has an aria-required html attribute' do + with_input_for @user, :name, :select, include_blank: true, input_html: {multiple: true}, collection: ['Jose' , 'Carlos'] + assert_select 'select.required' + assert_select 'select[aria-required]' + end + test 'input should allow disabled options with a lambda for collection select' do with_input_for @user, :name, :select, collection: ["Carlos", "Antonio"], disabled: lambda { |x| x == "Carlos" } From d189adf1497c118ebffbaa99c28f55c27bb3c3fa Mon Sep 17 00:00:00 2001 From: Cameron Cundiff Date: Sun, 7 Apr 2013 13:59:49 -0400 Subject: [PATCH 4/8] Test aria-required for datetime input. [#780] --- test/inputs/datetime_input_test.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/inputs/datetime_input_test.rb b/test/inputs/datetime_input_test.rb index e224ea91..404f4e4b 100644 --- a/test/inputs/datetime_input_test.rb +++ b/test/inputs/datetime_input_test.rb @@ -96,4 +96,10 @@ class DateTimeInputTest < ActionView::TestCase assert_select 'select.required' assert_select 'select[required]' end + + test 'date time input has an aria-required html attribute' do + with_input_for @user, :delivery_time, :time, required: true + assert_select 'select.required' + assert_select 'select[aria-required=true]' + end end From 61c83508bf32a8f3960f1b2f1fc9e15a8b006f89 Mon Sep 17 00:00:00 2001 From: Cameron Cundiff Date: Sun, 7 Apr 2013 14:00:58 -0400 Subject: [PATCH 5/8] Test aria-required for hidden inputs. [#780] --- test/inputs/hidden_input_test.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/inputs/hidden_input_test.rb b/test/inputs/hidden_input_test.rb index d86e5cba..19857f86 100644 --- a/test/inputs/hidden_input_test.rb +++ b/test/inputs/hidden_input_test.rb @@ -20,10 +20,11 @@ class HiddenInputTest < ActionView::TestCase assert_no_select 'label' end - test 'required/optional options should not be generated for hidden inputs' do + test 'required/aria-required/optional options should not be generated for hidden inputs' do with_input_for @user, :name, :hidden assert_no_select 'input.required' assert_no_select 'input[required]' + assert_no_select 'input[aria-required]' assert_no_select 'input.optional' assert_select 'input.hidden#user_name' end From 9cd202bc4f03bbf8f0d2a2d1d7f533470eec5fa9 Mon Sep 17 00:00:00 2001 From: Cameron Cundiff Date: Sun, 7 Apr 2013 14:02:49 -0400 Subject: [PATCH 6/8] Test for aria-required on priority input. [#780] --- test/inputs/priority_input_test.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/inputs/priority_input_test.rb b/test/inputs/priority_input_test.rb index b316ddf7..a7ce14c8 100644 --- a/test/inputs/priority_input_test.rb +++ b/test/inputs/priority_input_test.rb @@ -40,4 +40,10 @@ class PriorityInputTest < ActionView::TestCase assert_select 'select.required' assert_no_select 'select[required]' end + + test 'priority input should not generate invalid aria-required html attribute' do + with_input_for @user, :country, :country + assert_select 'select.required' + assert_no_select 'select[aria-required]' + end end From c142a73e22df897fc43976817ed80b02953d46a0 Mon Sep 17 00:00:00 2001 From: Cameron Cundiff Date: Sun, 7 Apr 2013 14:03:31 -0400 Subject: [PATCH 7/8] Include aria-required attribute on required fields. [Closes #780] --- lib/simple_form/inputs/base.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/simple_form/inputs/base.rb b/lib/simple_form/inputs/base.rb index a6d6f550..79fbd2ce 100644 --- a/lib/simple_form/inputs/base.rb +++ b/lib/simple_form/inputs/base.rb @@ -66,6 +66,7 @@ module SimpleForm @input_html_classes = @html_classes.dup @input_html_options = html_options_for(:input, input_html_classes).tap do |o| + o['aria-required'] = true if has_required? o[:readonly] = true if has_readonly? o[:disabled] = true if has_disabled? o[:autofocus] = true if has_autofocus? From 88e8ca2f775c0878328523ab3a0df206ee6f3286 Mon Sep 17 00:00:00 2001 From: Cameron Cundiff Date: Thu, 11 Apr 2013 08:20:32 -0400 Subject: [PATCH 8/8] Move aria-required option to html5 component. [Finishes #780] --- lib/simple_form/components/html5.rb | 5 ++++- lib/simple_form/inputs/base.rb | 1 - 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/simple_form/components/html5.rb b/lib/simple_form/components/html5.rb index cb513703..545b8f16 100644 --- a/lib/simple_form/components/html5.rb +++ b/lib/simple_form/components/html5.rb @@ -7,7 +7,10 @@ module SimpleForm def html5 @html5 = true - input_html_options[:required] = true if has_required? + if has_required? + input_html_options[:required] = true + input_html_options['aria-required'] = true + end nil end diff --git a/lib/simple_form/inputs/base.rb b/lib/simple_form/inputs/base.rb index 79fbd2ce..a6d6f550 100644 --- a/lib/simple_form/inputs/base.rb +++ b/lib/simple_form/inputs/base.rb @@ -66,7 +66,6 @@ module SimpleForm @input_html_classes = @html_classes.dup @input_html_options = html_options_for(:input, input_html_classes).tap do |o| - o['aria-required'] = true if has_required? o[:readonly] = true if has_readonly? o[:disabled] = true if has_disabled? o[:autofocus] = true if has_autofocus?