Follow WordPress time format on submission forms [#300]#305
Merged
Conversation
The event and announcement submission forms rendered Start/End time with a native <input type="time">, whose display format is dictated by the browser/OS locale rather than the site config. On some setups this forced 24-hour entry, which most US civilians find confusing. Add a shared TimeField React component that presents 12-hour (Hour/Minute/AM-PM) or 24-hour (Hour/Minute) selects based on a resolved format, while always emitting canonical HH:mm so storage and downstream display are unchanged. The format is resolved server-side from the WordPress "Time Format" setting by default and can be overridden per form via a new time_format shortcode option. 🐦⬛ Generated with Claude Code, orchestrated by Crow Co-Authored-By: Claude <noreply@anthropic.com> Crow-Session: F2C638F9-1488-416C-91D8-8924E2988AD6 Claude-Session: https://claude.ai/code/session_01RGXVGBiyvPyLCesFqS91d1
cef40b2 to
125ac62
Compare
render_event_form/render_announcement_form now read the WordPress "Time Format" setting via resolve_time_format(), so the Frontend unit tests must stub get_option. Add the mock in setUp so all form-render tests have it. 🐦⬛ Generated with Claude Code, orchestrated by Crow Co-Authored-By: Claude <noreply@anthropic.com> Crow-Session: F2C638F9-1488-416C-91D8-8924E2988AD6 Claude-Session: https://claude.ai/code/session_01RGXVGBiyvPyLCesFqS91d1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #300
Problem
The event and announcement submission forms rendered Start/End time with a native
<input type="time">. The displayed format of that element is dictated by the browser/OS locale, not by the plugin or WordPress — so on several sites it forced 24-hour ("military") time entry, which most US civilians find confusing. The value was always stored as canonical 24hHH:mm, and the Event Calendar / List / Post Edit already convert it to AM/PM for display — only the input side regressed.Fix
Shared
TimeFieldcomponent (assets/js/src/components/public/TimeField.js) presents:It parses the incoming
HH:mmvalue and always emits a canonical 24hHH:mmvia a synthetic change event, so form storage and all downstream display are unchanged.Server resolves the format (
includes/Frontend.php): a newresolve_time_format()helper derives12hour/24hourfrom the WordPress Settings → General → Time Format option by default, and bothrender_event_formandrender_announcement_formpass it to JS. A newtime_format="12hour|24hour"shortcode attribute can override per form.Applied to both
EventForm.jsandAnnouncementForm.js(both had the same native-input bug).Testing
npm run buildcompiles cleanly;php -lpasses onFrontend.php.19:30and displays as7:30 PM. With 24-hour, forms show 0–23 hour + minute and round-trip the same value.[mayo_event_form time_format="24hour"]overrides the WP option.🤖 Generated with Claude Code
https://claude.ai/code/session_01RGXVGBiyvPyLCesFqS91d1