Fix: frontend validation of number fields fails upon save (#5646)

This commit is contained in:
shamoon
2024-02-03 13:22:12 -08:00
committed by GitHub
parent 6b34f592df
commit 45e2b7f814
2 changed files with 28 additions and 16 deletions

View File

@@ -36,9 +36,18 @@ export class NumberComponent extends AbstractInputComponent<number> {
})
}
registerOnChange(fn: any): void {
this.onChange = (newValue: any) => {
// number validation
if (this.step === 1 && newValue?.toString().indexOf('e') === -1)
newValue = parseInt(newValue, 10)
if (this.step === 0.01) newValue = parseFloat(newValue).toFixed(2)
fn(newValue)
}
}
writeValue(newValue: any): void {
if (this.step === 1 && newValue?.toString().indexOf('e') === -1)
newValue = parseInt(newValue, 10)
// Allow monetary values to be displayed with 2 decimals
if (this.step === 0.01) newValue = parseFloat(newValue).toFixed(2)
super.writeValue(newValue)
}