Skip to content

Commit

Permalink
Makes it possible to enter 1 without a padded 0 in table row (#489)
Browse files Browse the repository at this point in the history
* Makes it possible to enter 1 without a padded 0 in the input field in TableRow.tsx

* lint

* lint

* rename
  • Loading branch information
henrikbossart authored Sep 11, 2023
1 parent 1f7fc46 commit 0e9592f
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion packages/dm-core-plugins/src/table/TableRow/TableRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,18 @@ export function TableRow(props: TTableRow) {
type={attributeType}
onChange={(event: ChangeEvent<HTMLInputElement>) => {
let newValue: string | number | boolean = event.target.value
if (attributeType === 'number') newValue = Number(newValue)
if (attributeType === 'number') {
const numberArray = Array.from(newValue)
if (
!numberArray.includes('.') &&
numberArray.length > 1 &&
Number(numberArray.at(0)) === 0
) {
newValue = newValue.slice(1)
event.target.value = newValue
}
newValue = Number(newValue)
}
updateItem(index, attribute, newValue)
}}
/>
Expand Down

0 comments on commit 0e9592f

Please sign in to comment.