Skip to content

Commit

Permalink
add whole number validation
Browse files Browse the repository at this point in the history
  • Loading branch information
RODO94 committed Oct 10, 2024
1 parent 11e9c1e commit 1dc37ad
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions editor.planx.uk/src/@planx/components/NumberInput/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,13 @@ export const numberInputValidationSchema = (input: NumberInput) =>
},
})
.test({
name: "whole number",
name: "check for a whole number",
message: "Enter a whole number",
test: (value: string | undefined) => {
if (input.onlyWholeNumbers && value?.includes(".")) {
if (!value) {
return false;
}
if (value.includes(".")) {
return false;
}
return true;
Expand Down

0 comments on commit 1dc37ad

Please sign in to comment.