fix(ui): line-item number inputs — allow clearing the 0 (store raw string, coerce at totals/save), unify value alignment, widen Množství column
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -87,9 +87,12 @@ interface OfferItem {
|
||||
id?: number;
|
||||
description: string;
|
||||
item_description: string;
|
||||
quantity: number;
|
||||
// Held as the raw typed string while editing so the field can be cleared
|
||||
// (an empty string renders fine in a type="number" input). Coerced via
|
||||
// Number(x) || 0 only where used (live totals + save payload).
|
||||
quantity: string | number;
|
||||
unit: string;
|
||||
unit_price: number;
|
||||
unit_price: string | number;
|
||||
is_included_in_total: boolean;
|
||||
}
|
||||
|
||||
@@ -323,10 +326,11 @@ function SortableItemRow({
|
||||
<TextField
|
||||
label="Množství"
|
||||
type="number"
|
||||
value={item.quantity}
|
||||
onChange={(e) => onUpdate("quantity", parseInt(e.target.value, 10))}
|
||||
value={item.quantity ?? ""}
|
||||
onChange={(e) => onUpdate("quantity", e.target.value)}
|
||||
slotProps={{ htmlInput: { step: "1" } }}
|
||||
InputProps={{ readOnly }}
|
||||
sx={{ "& input": { textAlign: "center" } }}
|
||||
/>
|
||||
<TextField
|
||||
label="Jednotka"
|
||||
@@ -337,10 +341,11 @@ function SortableItemRow({
|
||||
<TextField
|
||||
label="Jedn. cena"
|
||||
type="number"
|
||||
value={item.unit_price}
|
||||
onChange={(e) => onUpdate("unit_price", parseFloat(e.target.value))}
|
||||
value={item.unit_price ?? ""}
|
||||
onChange={(e) => onUpdate("unit_price", e.target.value)}
|
||||
slotProps={{ htmlInput: { step: "0.01" } }}
|
||||
InputProps={{ readOnly }}
|
||||
sx={{ "& input": { textAlign: "right" } }}
|
||||
/>
|
||||
</Box>
|
||||
<Box
|
||||
@@ -437,10 +442,11 @@ function SortableItemRow({
|
||||
<TableCell>
|
||||
<TextField
|
||||
type="number"
|
||||
value={item.quantity}
|
||||
onChange={(e) => onUpdate("quantity", parseInt(e.target.value, 10))}
|
||||
value={item.quantity ?? ""}
|
||||
onChange={(e) => onUpdate("quantity", e.target.value)}
|
||||
slotProps={{ htmlInput: { step: "1" } }}
|
||||
InputProps={{ readOnly }}
|
||||
sx={{ "& input": { textAlign: "center" } }}
|
||||
/>
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
@@ -453,10 +459,11 @@ function SortableItemRow({
|
||||
<TableCell>
|
||||
<TextField
|
||||
type="number"
|
||||
value={item.unit_price}
|
||||
onChange={(e) => onUpdate("unit_price", parseFloat(e.target.value))}
|
||||
value={item.unit_price ?? ""}
|
||||
onChange={(e) => onUpdate("unit_price", e.target.value)}
|
||||
slotProps={{ htmlInput: { step: "0.01" } }}
|
||||
InputProps={{ readOnly }}
|
||||
sx={{ "& input": { textAlign: "right" } }}
|
||||
/>
|
||||
</TableCell>
|
||||
<TableCell align="center">
|
||||
@@ -882,7 +889,14 @@ export default function OfferDetail() {
|
||||
const url = isEdit ? `${API_BASE}/offers/${id}` : `${API_BASE}/offers`;
|
||||
const payload: any = {
|
||||
...form,
|
||||
items: items.map((item, i) => ({ ...item, position: i })),
|
||||
items: items.map((item, i) => ({
|
||||
...item,
|
||||
// Coerce the raw typed strings back to numbers so an empty/partial
|
||||
// field never reaches the server as NaN (mirrors the totals math).
|
||||
quantity: Number(item.quantity) || 0,
|
||||
unit_price: Number(item.unit_price) || 0,
|
||||
position: i,
|
||||
})),
|
||||
sections: sections.map((s, i) => ({ ...s, position: i })),
|
||||
};
|
||||
if (!isEdit) delete payload.quotation_number;
|
||||
@@ -1524,7 +1538,7 @@ export default function OfferDetail() {
|
||||
#
|
||||
</TableCell>
|
||||
<TableCell>Popis</TableCell>
|
||||
<TableCell sx={{ width: "5.5rem" }} align="center">
|
||||
<TableCell sx={{ width: "7rem" }} align="center">
|
||||
Množství
|
||||
</TableCell>
|
||||
<TableCell sx={{ width: "5rem" }}>Jednotka</TableCell>
|
||||
|
||||
Reference in New Issue
Block a user