Repository: heartcombo/simple_form (Ruby)

Issue:
Support for weekday_select in Rails 7
Hi,

I would like to use the [weekday_select](https://edgeapi.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html#method-i-weekday_select) form helper.

In my particular case I have a model with an integer attribute called `weekday`, 0 to 6. Then the form looks like this:

```ruby
<%= form.weekday_select :weekday, { index_as_value: true }, class: 'form-select' %>
```

The nice thing here is that it automatically gets localized and translated.

Unfortunately I cannot find a way to use weekdays in Simple Form. Is it not supported, not documented, or am I just not looking at the right place?

Thanks!


Discussion:
Facing the same issue, hope this helps

You can create custom inputs and use `weekday_select` there https://github.com/heartcombo/simple_form#custom-inputs

Here is an example of mine, 

```ruby
# app/inputs/weekday_select_input.rb
# frozen_string_literal: true

class WeekdaySelectInput < SimpleForm::Inputs::CollectionSelectInput
  def input(wrapper_options = nil)
    merged_input_options = merge_wrapper_options(input_html_options, wrapper_options)

    @builder.weekday_select(attribute_name, input_options, merged_input_options)
  end
end
```

and use it in your views
```erb
<%= f.input :day_of_week, as: :weekday_select, index_as_value: true, include_blank: false %>
```
@ephracis @maful thanks for heads up! It's been implemented in master branch now!



Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 4d7d57da..ec90eaba 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,6 +1,7 @@
 ## Unreleased
 
 * Remove redundant `aria-required` attribute for required fields. [@aduth](https://github.com/aduth)
+* Add `weekday` input. [@nashby](https://github.com/nashby)
 
 ## 5.3.1
 
diff --git a/README.md b/README.md
index 1f516d9f..97dc60d0 100644
--- a/README.md
+++ b/README.md
@@ -621,6 +621,7 @@ Mapping         | Generated HTML Element               | Database Column Type
 `datetime`      | `datetime select`                    | `datetime/timestamp`
 `date`          | `date select`                        | `date`
 `time`          | `time select`                        | `time`
+`weekday`       | `select` (weekdays as options)       | -
 `select`        | `select`                             | `belongs_to`/`has_many`/`has_and_belongs_to_many` associations
 `radio_buttons` | collection of `input[type=radio]`    | `belongs_to` associations
 `check_boxes`   | collection of `input[type=checkbox]` | `has_many`/`has_and_belongs_to_many` associations
diff --git a/lib/simple_form/inputs.rb b/lib/simple_form/inputs.rb
index 2485d391..2476debf 100644
--- a/lib/simple_form/inputs.rb
+++ b/lib/simple_form/inputs.rb
@@ -22,5 +22,6 @@ module Inputs
     autoload :RichTextAreaInput
     autoload :StringInput
     autoload :TextInput
+    autoload :WeekdayInput
   end
 end
diff --git a/lib/simple_form/inputs/weekday_input.rb b/lib/simple_form/inputs/weekday_input.rb
new file mode 100644
index 00000000..131ae2cc
--- /dev/null
+++ b/lib/simple_form/inputs/weekday_input.rb
@@ -0,0 +1,14 @@
+# frozen_string_literal: true
+module SimpleForm
+  module Inputs
+    class WeekdayInput < CollectionSelectInput
+      enable :placeholder
+
+      def input(wrapper_options = nil)
+        merged_input_options = merge_wrapper_options(input_html_options, wrapper_options)
+
+        @builder.weekday_select(attribute_name, input_options, merged_input_options)
+      end
+    end
+  end
+end


Test patch:
diff --git a/test/inputs/weekday_input_test.rb b/test/inputs/weekday_input_test.rb
new file mode 100644
index 00000000..b8d80370
--- /dev/null
+++ b/test/inputs/weekday_input_test.rb
@@ -0,0 +1,19 @@
+# frozen_string_literal: true
+# encoding: UTF-8
+require 'test_helper'
+
+class WeekdayInputTest < ActionView::TestCase
+  test 'input generates a weekday select' do
+    if ActionView::VERSION::MAJOR >= 7
+      with_input_for @user, :born_at, :weekday
+      assert_select 'select.weekday#user_born_at'
+    end
+  end
+
+  test 'input generates a weekday select that accepts placeholder' do
+    if ActionView::VERSION::MAJOR >= 7
+      with_input_for @user, :born_at, :weekday, placeholder: 'Put in a weekday'
+      assert_select 'select.weekday[placeholder="Put in a weekday"]'
+    end
+  end
+end