Format number inputs with commas
Formats numeric input fields to display commas for every three digits.
This commit is contained in:
@@ -30,8 +30,27 @@ const AddTransactionButton = () => {
|
||||
}
|
||||
});
|
||||
|
||||
// Format number with commas
|
||||
const formatWithCommas = (value: string): string => {
|
||||
// Remove commas first to avoid duplicates when typing
|
||||
const numericValue = value.replace(/[^0-9]/g, '');
|
||||
return numericValue.replace(/\B(?=(\d{3})+(?!\d))/g, ',');
|
||||
};
|
||||
|
||||
const handleAmountChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
const formattedValue = formatWithCommas(e.target.value);
|
||||
form.setValue('amount', formattedValue);
|
||||
};
|
||||
|
||||
const onSubmit = (data: ExpenseFormValues) => {
|
||||
console.log('Expense data:', data);
|
||||
// Remove commas before processing the amount
|
||||
const numericAmount = data.amount.replace(/,/g, '');
|
||||
const processedData = {
|
||||
...data,
|
||||
amount: numericAmount
|
||||
};
|
||||
|
||||
console.log('Expense data:', processedData);
|
||||
setShowExpenseDialog(false);
|
||||
// 여기에서 실제 데이터 처리 로직을 구현할 수 있습니다
|
||||
};
|
||||
@@ -77,9 +96,9 @@ const AddTransactionButton = () => {
|
||||
<FormLabel>금액</FormLabel>
|
||||
<FormControl>
|
||||
<Input
|
||||
type="number"
|
||||
placeholder="0"
|
||||
{...field}
|
||||
value={field.value}
|
||||
onChange={handleAmountChange}
|
||||
/>
|
||||
</FormControl>
|
||||
</FormItem>
|
||||
|
||||
Reference in New Issue
Block a user