UX: allow ',' in input of floats, kerb height now accepts pfloat instead of pnat

This commit is contained in:
Pieter Vander Vennet 2025-05-09 17:20:02 +02:00
parent e2e3e4b51d
commit e7d3cb1886
3 changed files with 28 additions and 7 deletions

View file

@ -1,14 +1,22 @@
import { Translation } from "../../i18n/Translation"
import Translations from "../../i18n/Translations"
import { Validator } from "../Validator"
import FloatValidator from "./FloatValidator"
export default class PFloatValidator extends Validator {
export default class PFloatValidator extends FloatValidator {
constructor() {
super("pfloat", "A positive decimal number or zero")
}
isValid = (str) =>
!isNaN(Number(str)) && Number(str) >= 0 && !str.endsWith(".") && !str.endsWith(",")
isValid(str: string) {
if (!super.isValid(str)) {
return false
}
if (!FloatValidator.formattingHasComma) {
str = str.replace(",", ".")
}
const n = Number(str)
return n >= 0
}
getFeedback(s: string): Translation {
const spr = super.getFeedback(s)