diff --git a/lib/simple_form/inputs/collection_input.rb b/lib/simple_form/inputs/collection_input.rb index ee300ad0..ef8c5840 100644 --- a/lib/simple_form/inputs/collection_input.rb +++ b/lib/simple_form/inputs/collection_input.rb @@ -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. diff --git a/test/inputs/collection_select_input_test.rb b/test/inputs/collection_select_input_test.rb index 6b14d757..d5efcb27 100644 --- a/test/inputs/collection_select_input_test.rb +++ b/test/inputs/collection_select_input_test.rb @@ -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'