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

This commit is contained in:
shamoon authored and GitHub committed 2024-02-03 21:22:12 +00:00
1 parent 6b34f592df
commit 45e2b7f814
2 files changed
+28 -16

No files matched your search

@@ -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)
}