Fläche darf nur noch Integer sein

This commit is contained in:
Moritz Utcke
2025-09-25 11:41:28 -04:00
parent 6e3f749b07
commit c010bbaff0

View File

@@ -11,6 +11,22 @@
export let objekt: ObjektClient; export let objekt: ObjektClient;
export let ausweisart: Enums.Ausweisart; export let ausweisart: Enums.Ausweisart;
function onlyAllowIntegerInput(event: KeyboardEvent) {
const charCode = event.which || event.keyCode;
// Allow only numbers (0-9) and control keys (e.g., backspace)
if (charCode < 48 || charCode > 57) {
event.preventDefault();
}
}
function onlyAllowPastingIntegers(event: ClipboardEvent) {
const clipboardData = event.clipboardData || (window as any).clipboardData;
const pastedData = clipboardData.getData("Text");
if (!/^\d+$/.test(pastedData)) {
event.preventDefault();
}
}
</script> </script>
<div <div
@@ -100,6 +116,8 @@ xl:grid-cols-3 xl:gap-x-8 xl:gap-y-8
step="1" step="1"
required required
autocomplete="off" autocomplete="off"
on:keypress={onlyAllowIntegerInput}
on:paste={onlyAllowPastingIntegers}
bind:value={aufnahme.flaeche} bind:value={aufnahme.flaeche}
/> />
@@ -125,6 +143,8 @@ xl:grid-cols-3 xl:gap-x-8 xl:gap-y-8
type="number" type="number"
step="1" step="1"
required required
on:keypress={onlyAllowIntegerInput}
on:paste={onlyAllowPastingIntegers}
bind:value={aufnahme.nutzflaeche} bind:value={aufnahme.nutzflaeche}
/> />