prevent resetting number inputs with leading 0 while still typing

This commit is contained in:
Gani Georgiev committed 2026-07-17 22:00:08 +03:00
1 parent 6aa6b2c471
commit 09af56b342
11 files changed
+64 -12

No files matched your search

+10
View File
@@ -35,6 +35,16 @@ export function settings(props) {
placeholder: "Default to max ~5MB",
value: () => props.field.maxSize || "",
oninput: (e) => {
// temp skip invalid numbers with leading 0 while typing to avoid reseting the entire input
// (always normalized in onchange)
if (e.target.value?.length > 1 && e.target.value[0] == "0") {
return;
}
props.field.maxSize = parseInt(e.target.value, 10);
},
onchange: (e) => {
props.field.maxSize = null; // reset reactivity
props.field.maxSize = parseInt(e.target.value, 10);
},
}),
+13 -1
View File
@@ -252,7 +252,19 @@ export function settings(props) {
placeholder: "~5MB default",
name: () => `fields.${props.fieldIndex}.maxSize`,
value: () => props.field.maxSize || "",
oninput: (e) => (props.field.maxSize = parseInt(e.target.value, 10)),
oninput: (e) => {
// temp skip invalid numbers with leading 0 while typing to avoid reseting the entire input
// (always normalized in onchange)
if (e.target.value?.length > 1 && e.target.value[0] == "0") {
return;
}
props.field.maxSize = parseInt(e.target.value, 10);
},
onchange: (e) => {
props.field.maxSize = null; // reset reactivity
props.field.maxSize = parseInt(e.target.value, 10);
},
}),
),
t.div({ className: "field-help" }, "In bytes."),
+10
View File
@@ -35,6 +35,16 @@ export function settings(props) {
placeholder: "Default to max ~1MB",
value: () => props.field.maxSize || "",
oninput: (e) => {
// temp skip invalid numbers with leading 0 while typing to avoid reseting the entire input
// (always normalized in onchange)
if (e.target.value?.length > 1 && e.target.value[0] == "0") {
return;
}
props.field.maxSize = parseInt(e.target.value, 10);
},
onchange: (e) => {
props.field.maxSize = null; // reset reactivity
props.field.maxSize = parseInt(e.target.value, 10);
},
}),
+17 -1
View File
@@ -25,7 +25,23 @@ export function input(props) {
min: () => props.field.min,
max: () => props.field.max,
value: () => props.record[props.field.name] || 0,
oninput: (e) => props.record[props.field.name] = Number(e.target.value),
oninput: (e) => {
// temp skip invalid numbers with leading 0 while typing to avoid reseting the entire input
// (always normalized in onchange)
if (
e.target.value?.length > 1
&& e.target.value[0] == "0"
&& e.target.value[1] != "."
) {
return;
}
props.record[props.field.name] = Number(e.target.value);
},
onchange: (e) => {
props.record[props.field.name] = null; // reset reactivity
props.record[props.field.name] = Number(e.target.value);
},
}),
),
() => {