Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion frontend/src/entry-forms/Balance.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
--autocomplete-wrapper-flex="1"
/>
<input
type="tel"
type="text"
inputmode="decimal"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

According to MDN, this would show the decimal separator for the users locale - does that always allow entering a . as decimal separator as well?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

good catch. and actually the decimal input doesn't support the - either, so as I see it we could:

a) keep inputmode="decimal" for the good keypad and just normalize the separator (a typed locale ,.) before saving, since beancount/Decimal() only accept .. negatives will only work on desktop.
b) add a +/− toggle button next to the field. works on every keyboard, but doesn't really fit into the design. and we still need to normalize the value (option a).
c) change to type="number", which shows the full keyboard with -, . and all the special chars. downside is we lose the nice compact numeric keypad on mobile.

Here is a small example of the different inputs:
https://htmlpreview.github.io/?https://gist.githubusercontent.com/mekanics/30201fc5c7fb57a9aacb1a4b755aadeb/raw/2a470c4d4fc08ee345cba5ace2ad790ffb4168d3/index.html

I'm leaning towards c), but curious what you prefer.

pattern="-?[0-9.,]*"
placeholder={_("Number")}
size={10}
Expand Down
28 changes: 28 additions & 0 deletions frontend/test/entry-forms.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { equal, ok } from "node:assert/strict";
import { beforeEach, test } from "node:test";

import { flushSync, mount } from "svelte";

import { Balance } from "../src/entries/index.ts";
import BalanceForm from "../src/entry-forms/Balance.svelte";
import { setup_jsdom } from "./dom.ts";
import { initialiseLedgerData } from "./helpers.ts";

test.before(initialiseLedgerData);
beforeEach(setup_jsdom);

test("Balance form uses a decimal keyboard hint for the amount input", () => {
mount(BalanceForm, {
target: document.body,
props: {
entry: Balance.empty("2026-05-27"),
},
});
flushSync();

const input = document.body.querySelector('input[placeholder="Number"]');
ok(input instanceof HTMLInputElement);
equal(input.type, "text");
equal(input.inputMode, "decimal");
equal(input.pattern, "-?[0-9.,]*");
});
Loading