Fix 'aria-required' field generated by prompt

This commit is contained in:
Carlos Alberto 2019-10-19 14:57:27 -03:00
parent fe9e69945e
commit f9f6252238
2 changed files with 7 additions and 1 deletions

View File

@ -41,7 +41,7 @@ module SimpleForm
end
def has_required?
super && (input_options[:include_blank] || input_options[:prompt] || multiple?)
super && (input_options[:include_blank] || input_options[:prompt].present? || multiple?)
end
# Check if :include_blank must be included by default.

View File

@ -284,6 +284,12 @@ class CollectionSelectInputTest < ActionView::TestCase
assert_select 'select[required]'
end
test "collection input generated aria-label should contain 'true'" do
with_input_for @user, :age, :select, collection: 18..30, prompt: "Please select foo"
assert_select 'select.required'
assert_select 'select[aria-required=true]'
end
test 'collection input with select type does not generate required html attribute without blank option' do
with_input_for @user, :name, :select, include_blank: false, collection: %w[Jose Carlos]
assert_select 'select.required'