Skip to content

Date input support in Rails 7 #534

@ollietreend

Description

@ollietreend

The PR #526 by @mgrunberg, which was created to resolve issue #523, introduced the assumption that Rails 7 will always render date fields as <input type="date">. However, it's still possible for Rails 7 to render <select> based date inputs.

According to the Rails Form Helpers guide:

If you do not wish to use HTML5 date and time inputs, Rails provides alternative date and time form helpers that render plain select boxes.

There are now two officially supported form helper methods:

  • form.date_field will output <input type="date"> (new in Rails 7)
  • form.date_select will output <select> fields (traditional Rails date input)

However when using Rails 7, only <input type="date"> fields are supported because:

if ::Rails::VERSION::MAJOR >= 7
# Rails 7 generates date fields using input type="date". Capybara support's them
fill_in options[:from], with: date
else
base_dom_id = get_base_dom_id_from_label_tag(options[:from])
find(:xpath, ".//select[@id='#{base_dom_id}_1i']").select(date.year.to_s)
find(:xpath, ".//select[@id='#{base_dom_id}_2i']").select(I18n.l(date, format: '%B'))
find(:xpath, ".//select[@id='#{base_dom_id}_3i']").select(date.day.to_s)
end

👓 What did you see?

Cucumber no longer knows how to select dates for input fields created with form.date_select in Rails 7.

✅ What did you expect to see?

Cucumber should still be able to select dates, regardless of whether form.date_field or form.date_select was used in Rails 7.

📦 Which version are you using?

  • cucumber-rails 2.5.0
  • Rails 7

🔬 How could we reproduce it?

  1. Install Rails 7 with cucumber-rails 2.5.0
  2. Render a form with a date field created using form.date_select
  3. Cucumber cannot select a date for this field

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions