Skip to content

Commit 4f7b1a1

Browse files
Copilothuangyiirene
andcommitted
Fix type conversion for number and date inputs
Co-authored-by: huangyiirene <7665279+huangyiirene@users.noreply.github.com>
1 parent 9b7358e commit 4f7b1a1

1 file changed

Lines changed: 28 additions & 5 deletions

File tree

packages/components/src/ui/filter-builder.tsx

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -211,15 +211,38 @@ function FilterBuilder({
211211
}
212212

213213
// Default input for text, number, date
214+
const inputType = getInputType(condition.field)
215+
216+
// Format value based on field type
217+
const formatValue = () => {
218+
if (!condition.value) return ""
219+
if (inputType === "date" && typeof condition.value === "string") {
220+
// Ensure date is in YYYY-MM-DD format
221+
return condition.value.split('T')[0]
222+
}
223+
return String(condition.value)
224+
}
225+
226+
// Handle value change with proper type conversion
227+
const handleValueChange = (newValue: string) => {
228+
let convertedValue: string | number | boolean = newValue
229+
230+
if (field?.type === "number" && newValue !== "") {
231+
convertedValue = parseFloat(newValue) || 0
232+
} else if (field?.type === "date") {
233+
convertedValue = newValue // Keep as ISO string
234+
}
235+
236+
updateCondition(condition.id, { value: convertedValue })
237+
}
238+
214239
return (
215240
<Input
216-
type={getInputType(condition.field)}
241+
type={inputType}
217242
className="h-9 text-sm"
218243
placeholder="Value"
219-
value={String(condition.value || "")}
220-
onChange={(e) =>
221-
updateCondition(condition.id, { value: e.target.value })
222-
}
244+
value={formatValue()}
245+
onChange={(e) => handleValueChange(e.target.value)}
223246
/>
224247
)
225248
}

0 commit comments

Comments
 (0)