Fix for number field validation and behaviour, addition of currency constraint validation #1605
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What's in this Pull Request?
There is some overlap with the PR here - #1601 (comment)
I don't believe my branch, with the changes I've made, has the issue referenced in #1592
This PR makes a few different changes:
Fixes number validation issues
onSubmitClick
inDynamicForm.tsx
- current code does some validation to determine whether the form should actually save a list item or not. The Number validation added to better support min and max number settings (in this commit 8998b5d) added logic here in anelse
statement followingif (val.isRequired)
. This means that even if a field is violating it's own min and max constraints - the form is only preventing save when the field isn't required. I have changed this logic to capture constraint violations that occur whether the field is required or not.Fixes native number input behaviour when using keys / scroll
<TextField/>
accepts attributes common toHTMLInputElement
- which is whytype="number"
andtype="password"
among others would work. Pressing the up or down keys or using the mouse wheel while a number field has focus causes the number to go up or down in value. This can be constrained by min and max values if they are provided, but they were not. By pulling them in, we now get correct behaviour - numbers do not go above or below the bounds set in list settings.Extending of number validation behaviour to Currency fields, and enhancement of error message to format values as currency
PnP/sp
. Using the addedCurrencyMap.ts
file included in this PR, the LCID set on any currency field can be converted to a culture tag likeen-GB
. If the lookup fails, we use the culture provided inpageContext
instead. This can then be used withIntl.NumberFormat
to display values correctly - so if a currency field has a maximum value of 50 - the error message will now say "Value must be lower than £50.00". If we were sure available languages in SPO will remain fairly static, the call to regional settings could be replaced with another mapping object (aRecord<number,string>
object etc).