Merge pull request #781 from ckundo/780-aria-required

Include aria-required attribute on required fields
This commit is contained in:
Rafael Mendonça França 2013-04-11 07:05:11 -07:00
commit d8d0cae253
7 changed files with 55 additions and 2 deletions

View File

@ -7,7 +7,10 @@ module SimpleForm
def html5 def html5
@html5 = true @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 nil
end end

View File

@ -23,6 +23,12 @@ class CollectionCheckBoxesInputTest < ActionView::TestCase
assert_no_select 'input[required]' assert_no_select 'input[required]'
end 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 test 'input should do automatic collection translation for check_box types using defaults key' do
store_translations(:en, simple_form: { options: { defaults: { store_translations(:en, simple_form: { options: { defaults: {
gender: { male: 'Male', female: 'Female'} gender: { male: 'Male', female: 'Female'}

View File

@ -140,6 +140,12 @@ class CollectionRadioButtonsInputTest < ActionView::TestCase
assert_select 'input[type=radio][required]' assert_select 'input[type=radio][required]'
end 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 test 'input radio does not wrap the collection by default' do
with_input_for @user, :active, :radio_buttons with_input_for @user, :active, :radio_buttons

View File

@ -176,6 +176,7 @@ class CollectionSelectInputTest < ActionView::TestCase
with_input_for @user, :name, :select, include_blank: false, collection: ['Jose' , 'Carlos'] with_input_for @user, :name, :select, include_blank: false, collection: ['Jose' , 'Carlos']
assert_select 'select.required' assert_select 'select.required'
assert_no_select 'select[required]' assert_no_select 'select[required]'
assert_no_select 'select[aria-required=true]'
end end
test 'collection input with select type with multiple attribute should generate required html attribute without blank option' do 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]' assert_select 'select[required]'
end 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 test 'input should allow disabled options with a lambda for collection select' do
with_input_for @user, :name, :select, collection: ["Carlos", "Antonio"], with_input_for @user, :name, :select, collection: ["Carlos", "Antonio"],
disabled: lambda { |x| x == "Carlos" } disabled: lambda { |x| x == "Carlos" }

View File

@ -96,4 +96,10 @@ class DateTimeInputTest < ActionView::TestCase
assert_select 'select.required' assert_select 'select.required'
assert_select 'select[required]' assert_select 'select[required]'
end 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 end

View File

@ -20,10 +20,11 @@ class HiddenInputTest < ActionView::TestCase
assert_no_select 'label' assert_no_select 'label'
end 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 with_input_for @user, :name, :hidden
assert_no_select 'input.required' assert_no_select 'input.required'
assert_no_select 'input[required]' assert_no_select 'input[required]'
assert_no_select 'input[aria-required]'
assert_no_select 'input.optional' assert_no_select 'input.optional'
assert_select 'input.hidden#user_name' assert_select 'input.hidden#user_name'
end end

View File

@ -40,4 +40,10 @@ class PriorityInputTest < ActionView::TestCase
assert_select 'select.required' assert_select 'select.required'
assert_no_select 'select[required]' assert_no_select 'select[required]'
end 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 end