Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for weekday_select in Rails 7 #1770

Closed
ephracis opened this issue Apr 22, 2022 · 2 comments · Fixed by #1846
Closed

Support for weekday_select in Rails 7 #1770

ephracis opened this issue Apr 22, 2022 · 2 comments · Fixed by #1846

Comments

@ephracis
Copy link

Hi,

I would like to use the 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:

<%= 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!

@maful
Copy link

maful commented Nov 15, 2023

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,

# 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

<%= f.input :day_of_week, as: :weekday_select, index_as_value: true, include_blank: false %>

nashby added a commit that referenced this issue Jun 29, 2024
nashby added a commit that referenced this issue Jul 12, 2024
@nashby
Copy link
Collaborator

nashby commented Jul 12, 2024

@ephracis @maful thanks for heads up! It's been implemented in master branch now!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

3 participants