Altinn / Altinn/app-frontend-react
Validation of `multipleOf` keyword with decimals fails sporadically
- Dominant language
- TypeScript
- Stars
- 21
- Forks
- 33
- Avg merge
- 6d 23h
- Merged PRs (30d)
- 3
Description
### Description of the bug
When validation against a schema like
```json
{
"properties": {
"test": {
"type": "number",
"multipleOf": 0.1,
}
}
}
```
The validation fails on valid numbers. F.ex. here, where `multipleOf: 0.1` should result in `855,8` being a valid number.

In addition, we are missing standard text for the validation error message for `multipleOf` keyword.
### Steps To Reproduce
1. Go to an app and modify the data model so that one of the fields has the `multipleOf` keyword set to `0.1` (for `type: number` fields).
2. Type some different numbers into the field: `1.1`, `1.2`, `1.3`, etc, and see that some of them will result in a validation error.
### Additional Information
This seems to be a known rounding issue, see https://github.com/ajv-validator/ajv/issues/652.
It can be fixed either by specifying an option `multipleOfPrecision` to the validator, or by re-implementing that keyword with our own method.
Contributor guide
Research direction
Reproduce the issue using a data model with a number field and `multipleOf: 0.1`, then inspect how validation is integrated in the frontend. Compare the rounding behavior with the linked AJV issue and choose an approach that fits the project. Done means decimal multiples such as 1.1, 1.2, 1.3, and 855.8 validate consistently and a standard `multipleOf` error message is available.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100