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

Date input support in Rails 7 #534

Closed
ollietreend opened this issue Mar 14, 2022 · 3 comments · Fixed by #535
Closed

Date input support in Rails 7 #534

ollietreend opened this issue Mar 14, 2022 · 3 comments · Fixed by #535
Labels
🐛 bug Defect / Bug good first issue Good for newcomers

Comments

@ollietreend
Copy link

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
@luke-hill
Copy link
Contributor

So what we missed with this was extra cucumber tests to validate both options still worked. I'll add these in to start with and then we can go about rectifying this.

@ollietreend
Copy link
Author

@luke-hill @mgrunberg Thank you both for the super quick work on this! ⭐ 🙇🏻 It's really appreciated.

Is it going to make its way into a release shortly?

@luke-hill
Copy link
Contributor

I'll give it a few days to see if any other things come out. But I can try cut a bugfix release for this soon

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Defect / Bug good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants