Skip to content

Commit

Permalink
fix: extract the number correctly from the editable column value
Browse files Browse the repository at this point in the history
  • Loading branch information
hamed-musallam committed Aug 30, 2023
1 parent a884085 commit 0e11fd6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/component/elements/EditableColumn.tsx
Expand Up @@ -11,6 +11,14 @@ import {

import Input, { InputProps } from './Input';

function extractNumber(val: string | number, type: string) {
if (type === 'number' && typeof val !== 'number') {
return Number(val.replaceAll(/[^\d.-]/g, ''));
}

return val;
}

interface EditableColumnProps
extends Omit<InputProps, 'style' | 'value' | 'type'> {
onSave?: (element: any) => void;
Expand Down Expand Up @@ -41,8 +49,7 @@ const EditableColumn = forwardRef(function EditableColumn(

const [enabled, enableEdit] = useState<boolean | undefined>();
const [isValid, setValid] = useState<boolean>(true);
const [val, setVal] = useState(value);

const [val, setVal] = useState(extractNumber(value, type));
useEffect(() => {
enableEdit(editStatus);
}, [editStatus]);
Expand Down
1 change: 1 addition & 0 deletions src/component/panels/IntegralsPanel/IntegralTable.tsx
Expand Up @@ -139,6 +139,7 @@ function IntegralTable({ activeTab, data, info }: IntegralTableProps) {

return (
<EditableColumn
key={`${integral}`}
value={integral}
onSave={(event) => saveRelativeHandler(event, row.original)}
type="number"
Expand Down

0 comments on commit 0e11fd6

Please sign in to comment.