Skip to content

fix: use text input for date variables to respect Joplin date format …#146

Open
sh1vam31 wants to merge 1 commit intojoplin:masterfrom
sh1vam31:fix/date-variable-respects-locale-settings_#112
Open

fix: use text input for date variables to respect Joplin date format …#146
sh1vam31 wants to merge 1 commit intojoplin:masterfrom
sh1vam31:fix/date-variable-respects-locale-settings_#112

Conversation

@sh1vam31
Copy link
Copy Markdown
Contributor

Fixes #112 — Template dialog UI should respect the date locale settings

Description

The native HTML5 <input type="date"> in Chromium (used by Electron/Joplin) hardcodes its display format to the OS locale and completely ignores Joplin's Tools → Options → Date format setting. For example, a user with YYYY-MM-DD configured in Joplin always sees mm/dd/yyyy in the template dialog.

Fix: Replaced type="date" with type="text" that shows the user's configured Joplin date format as a placeholder (e.g., YYYY-MM-DD). The format is injected from DateAndTimeUtils at dialog render time.

Before fix:

Screen.Recording.2026-02-26.at.1.10.26.AM.mov

After fix:

Screen.Recording.2026-02-26.at.1.18.09.AM.mov

How to test

  1. Go to Tools → Options → General → set Date format to YYYY-MM-DD
  2. Create a note with the template tag and this content:

start_date:
type: date
label: "Pick a start date:"

Start: {{ start_date }}

  1. Go to Tools → Templates → Create note from template
  2. Before fix: The date field shows mm/dd/yyyy ignoring your setting
  3. After fix: The date field shows YYYY-MM-DD as a placeholder, matching your Joplin setting exactly

@sh1vam31
Copy link
Copy Markdown
Contributor Author

@alondmnt, @nishantwrp, Kindly review this PR

// Use type="text" instead of type="date" to bypass Chromium's OS-locale
// date picker, which ignores Joplin's date format setting (issue #112).
// The placeholder shows the user's configured format as a hint.
return `<input name="${encode(this.name)}" type="text" placeholder="${encode(this.dateFormat)}" pattern="\\d{4}-\\d{2}-\\d{2}"></input>`;
Copy link
Copy Markdown
Collaborator

@nishantwrp nishantwrp Feb 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't there an option to give locale to <input type="date">?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the question, I did look into this — unfortunately, Chromium ignores the lang attribute and all HTML locale hints for . The display format is controlled purely by the OS locale, not the page settings. This is a known limitation even in Electron.

Switching to type="text" with a placeholder showing the user's Joplin date format was the only reliable workaround I found. Happy to explore any other approach if you have one in mind!

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. I think text would be inconvenient for the users when compared to a native date-picker.

Maybe, we can explore some small custom date picker component (maybe https://www.npmjs.com/package/react-datepicker). Maybe need some additional work to comply with joplin theming but maybe that is something that can be done in follow-up.

@sh1vam31 sh1vam31 force-pushed the fix/date-variable-respects-locale-settings_#112 branch 2 times, most recently from 3d1d498 to 9778666 Compare February 28, 2026 19:34
@sh1vam31
Copy link
Copy Markdown
Contributor Author

Updated! I've replaced the type="text" workaround with a flatpickr custom date picker. It respects the user's Joplin date format, shows a native-feeling calendar UI, supports both clicking and typing, and adapts to Joplin's theme.

joplin#112)

- Replaced <input type="date"> with a flatpickr-powered custom date picker
- flatpickr is initialized in datepicker.js using the user's configured Joplin
  date format (e.g. YYYY-MM-DD), converted from moment.js to flatpickr tokens
- Added a year dropdown so users can jump to any year quickly (±10 years)
- The calendar theme is adapted to Joplin's dark/light CSS variables
- Date format is injected into each DateCustomVariable via setDateFormat()
  called from parser.ts before the dialog is rendered
@sh1vam31 sh1vam31 force-pushed the fix/date-variable-respects-locale-settings_#112 branch from 9778666 to 3681032 Compare February 28, 2026 19:39
overflow: auto;
}

/* ── Flatpickr: make the calendar fit the dialog and match Joplin theme ── */
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you move these to src/views/flatpicker-overrides.css

}

th, td {
th,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you revert these linting changes, helps keep the diff small and focus on whats actually changed

// so the placeholder matches their configured format (fixes issue #112).
for (const variable of Object.values(variableObjects)) {
if (variable instanceof DateCustomVariable) {
variable.setDateFormat(this.utils.getDateFormat());
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why can't this be done inside "src/variables/types/date.ts"?

@alondmnt
Copy link
Copy Markdown
Collaborator

Hi @sh1vam31, friendly reminder on the outstanding review comments: the CSS split, linting revert, and moving the format injection into date.ts. Let us know if you need any help.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Template dialog UI should respect the date locale settings

3 participants