Skip to content

Commit

Permalink
Fix 'aria-required' field generated by prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
CarlosAlbertoSantoss committed Oct 19, 2019
1 parent fe9e699 commit f9f6252
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/simple_form/inputs/collection_input.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def collection
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.
Expand Down
6 changes: 6 additions & 0 deletions test/inputs/collection_select_input_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit f9f6252

Please sign in to comment.