fix: prevent number input reset to 0 when clearing value in rule form
Some checks failed
Deploy MyApp on Same Server / build-and-deploy (push) Has been cancelled

Avoid converting empty string to 0 in value1 and value2 number inputs, which caused unexpected behavior in some browsers when users cleared the field.
This commit is contained in:
2026-05-31 22:38:38 +03:30
parent 9da69c96b1
commit 9ec7187e07

View File

@@ -98,7 +98,14 @@ export function RuleFormCard({ rule, index, totalRules, onUpdate, onRemove }: Ru
type="number"
step="0.01"
value={rule.value1}
onChange={(e) => onUpdate(index, { value1: Number(e.target.value) })}
onChange={(e) => {
const val = e.target.value
// Only update if value is not empty; otherwise keep previous value
// to avoid Number('') → 0 breaking the input in some browsers
if (val !== '') {
onUpdate(index, { value1: Number(val) })
}
}}
className="w-full px-3 py-2 pl-10 bg-white border border-orange-200 rounded-lg text-sm font-medium focus:ring-2 focus:ring-orange-500 focus:border-orange-500"
placeholder={needsMax ? 'از' : 'مقدار'}
required
@@ -115,7 +122,14 @@ export function RuleFormCard({ rule, index, totalRules, onUpdate, onRemove }: Ru
type="number"
step="0.01"
value={rule.value2 ?? ''}
onChange={(e) => onUpdate(index, { value2: Number(e.target.value) })}
onChange={(e) => {
const val = e.target.value
// Only update if value is not empty; otherwise keep previous value
// to avoid Number('') → 0 breaking the input in some browsers
if (val !== '') {
onUpdate(index, { value2: Number(val) })
}
}}
className="w-full px-3 py-2 pl-10 bg-white border border-orange-200 rounded-lg text-sm font-medium focus:ring-2 focus:ring-orange-500 focus:border-orange-500"
placeholder="تا"
required