Skip to content

Commit cfdf38f

Browse files
committed
fix(tables): let the row modal accept formatted amounts again
Found by Cursor Bugbot. I unified the row modal's input type with the grid's `inputMode` last round, but in the wrong direction: mapping `inputMode: 'decimal'` to `<input type="number">` made the modal reject $1,234.56, 1.234,56 and (12.00) — the exact formats `parseCurrencyInput` exists to accept, and which the grid's inline editor takes fine. A native number input and a numeric keypad are different things. Types whose parser accepts formatted text now say so, and get a text field with `inputMode='decimal'` — the shape the grid already uses. A plain number keeps the native input, its spinner, and its validation.
1 parent 13a2326 commit cfdf38f

4 files changed

Lines changed: 23 additions & 3 deletions

File tree

apps/sim/app/workspace/[workspaceId]/tables/[tableId]/components/row-modal/row-modal.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -302,9 +302,12 @@ function ColumnField({ column, value, onChange }: ColumnFieldProps) {
302302
title={title}
303303
required={column.required}
304304
hint={hint}
305-
// Registry-driven, so a numeric type can't get the numeric keypad in the
306-
// grid's inline editor but a plain text field here (currency did).
307-
inputType={definition.inputMode === 'decimal' ? 'number' : 'text'}
305+
// A native number input rejects the formatted amounts this type's parser
306+
// exists to accept, so those types take a text field — the same shape the
307+
// grid's inline editor uses.
308+
inputType={
309+
definition.inputMode === 'decimal' && !definition.acceptsFormattedInput ? 'number' : 'text'
310+
}
308311
value={formatValueForInput(value, column.type)}
309312
onChange={onChange}
310313
placeholder={`Enter ${column.name}`}

apps/sim/lib/table/__tests__/column-type-registry.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,15 @@ describe('registry shape', () => {
6767
}
6868
})
6969

70+
it('never asks for a native number input on a type accepting formatted text', () => {
71+
// `<input type="number">` rejects `$1,234.56` outright, so a type whose
72+
// parser exists to accept that must get a text field with a numeric keypad.
73+
for (const definition of ALL_COLUMN_TYPES) {
74+
if (!definition.acceptsFormattedInput) continue
75+
expect(definition.inputMode).toBe('decimal')
76+
}
77+
})
78+
7079
it('gives every type that can reject a draft a message to show', () => {
7180
// Without one, `cleanCellValue` nulls the draft and the edit vanishes with
7281
// no explanation.

apps/sim/lib/table/column-types/currency.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export const currencyColumnType: ColumnTypeDefinition = {
2121
editor: 'text',
2222
expandable: false,
2323
inputMode: 'decimal',
24+
acceptsFormattedInput: true,
2425
// Also accepts the grouping separator and the symbol the user is likely to
2526
// type first — `parseCurrencyInput` strips both.
2627
typeaheadPattern: /[\d.,\-\p{Sc}]/u,

apps/sim/lib/table/column-types/types.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,13 @@ export interface ColumnTypeDefinition {
133133
readonly expandable: boolean
134134
/** `inputMode` for the text editor, when the type wants a specific keypad. */
135135
readonly inputMode?: 'decimal'
136+
/**
137+
* Whether the editor must accept text an `<input type="number">` would reject.
138+
* A currency cell legitimately takes `$1,234.56` or `1.234,56`, so it needs a
139+
* text input with a numeric keypad; a plain number takes neither and keeps
140+
* the native numeric input with its spinner and validation.
141+
*/
142+
readonly acceptsFormattedInput?: boolean
136143
/**
137144
* Keys that may start a type-ahead edit. Absent means any printable key
138145
* starts one — only types that parse their input restrict it, so a stray

0 commit comments

Comments
 (0)