-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Whole number option on Number Input #3798
Changes from 3 commits
4e061e3
762ca0e
289e7bd
b12694e
ec6e53e
967cc14
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ export interface NumberInput extends BaseNodeData { | |
fn?: string; | ||
units?: string; | ||
allowNegatives?: boolean; | ||
onlyWholeNumbers?: boolean; | ||
} | ||
|
||
export type UserData = number; | ||
|
@@ -28,6 +29,7 @@ export const parseNumberInput = ( | |
fn: data?.fn || "", | ||
units: data?.units, | ||
allowNegatives: data?.allowNegatives || false, | ||
onlyWholeNumbers: data?.onlyWholeNumbers || false, | ||
RODO94 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
...parseBaseNodeData(data), | ||
}); | ||
|
||
|
@@ -52,6 +54,19 @@ export const numberInputValidationSchema = (input: NumberInput) => | |
} | ||
return value === "0" ? true : Boolean(parseNumber(value)); | ||
}, | ||
}) | ||
.test({ | ||
name: "check for a whole number", | ||
message: "Enter a whole number", | ||
test: (value: string | undefined) => { | ||
if (!value) { | ||
return false; | ||
} | ||
if (input.onlyWholeNumbers && !Number.isInteger(Number(value))) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried a few different ways of validating the whole number. Using the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
return false; | ||
} | ||
return true; | ||
}, | ||
}); | ||
|
||
export const validationSchema = (input: NumberInput) => | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit:
not.toHaveBeenCalled()
might be more meaningful & definitive check here? Because we want to check if the error blocks submission, not that it was possibly automatically rounded tofahrenheit: 10
and successfully submitted for example!