Skip to content

Commit fa14cbb

Browse files
authored
fix decimal input in amount input boxes (#5831)
* preserve decimal seperators while typing in input boxes * note
1 parent 1210a74 commit fa14cbb

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

packages/loot-core/src/shared/rules.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@ import { t } from 'i18next';
33

44
import { FieldValueTypes, RuleConditionOp } from '../types/models';
55

6-
import { integerToAmount, amountToInteger, currencyToAmount } from './util';
6+
import {
7+
integerToAmount,
8+
amountToInteger,
9+
currencyToAmount,
10+
getNumberFormat,
11+
} from './util';
712

813
// For now, this info is duplicated from the backend. Figure out how
914
// to share it later.
@@ -374,10 +379,22 @@ export function makeValue(value, cond) {
374379
switch (cond.type) {
375380
case 'number': {
376381
if (cond.op !== 'isbetween') {
382+
const stringValue = String(value);
383+
const { decimalSeparator } = getNumberFormat();
384+
385+
// preserve trailing decimal separator to allow decimal input during typing
386+
if (stringValue && stringValue.endsWith(decimalSeparator)) {
387+
return {
388+
...cond,
389+
error: null,
390+
value: stringValue,
391+
};
392+
}
393+
377394
return {
378395
...cond,
379396
error: null,
380-
value: value ? currencyToAmount(String(value)) || 0 : 0,
397+
value: value ? currencyToAmount(stringValue) || 0 : 0,
381398
};
382399
}
383400
break;

upcoming-release-notes/5831.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
category: Bugfix
3+
authors: [matt-fidd]
4+
---
5+
6+
Allow decimals numbers to be typed into amount filter

0 commit comments

Comments
 (0)