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 5319412dac
commit cd0400fc51
3 changed files with 28 additions and 7 deletions

View file

@ -6,15 +6,28 @@ import { ValidatorType } from "../Validators"
export default class FloatValidator extends Validator {
inputmode: "decimal" = "decimal" as const
protected static readonly formattingHasComma = ("" + 1.42).indexOf(",") > 0
constructor(name?: ValidatorType, explanation?: string) {
super(name ?? "float", explanation ?? "A decimal number", "decimal")
}
isValid(str) {
/**
*
* new FloatValidator().isValid("0,2") // => true
*/
isValid(str: string) {
console.log("Is valid?", str, FloatValidator.formattingHasComma)
if (!FloatValidator.formattingHasComma) {
str = str.replace(",", ".")
}
return !isNaN(Number(str)) && !str.endsWith(".") && !str.endsWith(",")
}
reformat(str): string {
reformat(str: string): string {
if (!FloatValidator.formattingHasComma) {
str = str.replace(",", ".")
}
return "" + Number(str)
}