Fix week display format persisting after Turbo requests#441
Conversation
Changed the date picker value from @chosen_date to @chosen_date.iso8601 to ensure proper ISO 8601 formatting (YYYY-MM-DD). This prevents the date from briefly displaying in the default Ruby Date format after Turbo requests and before flatpickr re-initializes. Fixes #439 Co-authored-by: Kasper Høglund <kaospr@users.noreply.github.com>
Pull Request ReviewSummaryThis PR fixes a UI bug where the week display format ("Week 3") was reverting to a date format ("01-01-2026") after Turbo requests. The fix is minimal, targeted, and effective. ✅ Code Quality & Best PracticesStrengths:
Observations:
🐛 Potential IssuesNone identified. The change is safe because:
⚡ Performance ConsiderationsNo concerns. The
🔒 Security ConcernsNone. This change:
🧪 Test CoverageRecommendation: Consider adding a test to prevent regression, though this is a minor UI fix. A system test could verify:
Example location: However, testing JavaScript-dependent UI behavior may require Selenium/Capybara setup that might be overkill for this specific fix. The CLAUDE.md indicates system tests are available with Capybara/Selenium, so infrastructure exists if desired. 📋 Additional NotesContext validation:
Minor observation: The Verdict: ✅ APPROVEDThis is a clean, well-understood fix for a specific UI bug. The change is minimal, safe, and addresses the root cause. No blocking issues identified. Optional enhancement: Consider adding a regression test, but this is not blocking for merge. Great work tracking down the Turbo/flatpickr interaction issue! 🤖 |
|
Claude finished @kaospr's task in 1m 38s —— View job Root Cause Identified! ✅You were absolutely right about Turbo Morph! Here's what I found: The Problem: In <%= turbo_refresh_method_tag :morph %>When flatpickr initializes, it creates an alternative input ( After form submission, Turbo Morph morphs the DOM instead of replacing it. During morphing, the The Solution: We need to tell Turbo to skip morphing the date picker input by adding Proposed FixAdd <%= form_with url: root_path, method: :get, class: "flex items-stretch" do |form| %>
<%= form.text_field :date,
id: "date_picker_input",
value: @chosen_date.iso8601,
class: "flex text-sm md:text-base px-1 md:px-2 cursor-pointer border-none text-center hover:text-primary-600 z-10 focus:ring-0 font-medium",
data: {
turbo_permanent: true,
controller: "flatpickr",
flatpickr_auto_submit_value: true,
flatpickr_fit_width_value: true,
flatpickr_locale_value: I18n.locale,
flatpickr_week_numbers: true,
flatpickr_alt_input: true,
flatpickr_alt_format: "[#{t("common.week")}] W",
}
%>
<% end %>The key changes:
This tells Turbo to skip this element during page morphs, preserving the flatpickr-enhanced DOM structure. Todo List:
Should I implement this fix?Let me know if you'd like me to apply this change, or if you'd prefer to test it yourself first! |
@claude Go ahead |
|
Claude finished @kaospr's task in 1m 2s —— View job Turbo Morph Fix Implemented ✅Changes Made: Added <%= form.text_field :date,
id: "date_picker_input",
value: @chosen_date.iso8601,
class: "...",
data: {
turbo_permanent: true, # ← Added
controller: "flatpickr",
# ... other attributes
}
%>What This Does: The Without this fix, Turbo Morph would replace the flatpickr-created Testing: Please test by:
Commit: |
…reaking flatpickr When Turbo Morph is enabled, it morphs the DOM instead of replacing it. Flatpickr creates an alternative input element that displays the formatted week text, but Turbo Morph replaces this element during page updates. By adding data-turbo-permanent with a unique id, we tell Turbo to skip morphing this element, preserving the flatpickr-enhanced DOM structure across page updates. Co-authored-by: Kasper Høglund <kaospr@users.noreply.github.com>
Code Review for PR #441I've reviewed the changes to fix the week display format issue. Here's my comprehensive feedback: ✅ Positive Aspects1. Root Cause Correctly Identified 2. Consistent Redirect Behavior 3. Turbo Morph Handling
|
Summary
Fixed the bug where the week display in the time registration page changed from "Week 3" to a date format like "01-01-2026" after submitting a time registration.
Root Cause
The flatpickr date picker's input field had
value: @chosen_datewhich rendered as a Ruby Date object. After Turbo requests, this would briefly display as a date string before flatpickr re-initialized to show the week format.Solution
Changed the value to
@chosen_date.iso8601inapp/views/time_regs/_date_picker.html.erb:2to ensure proper ISO 8601 formatting (YYYY-MM-DD) that flatpickr can correctly parse and display with the configured week format.Fixes #439
🤖 Generated with Claude Code