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
Added validation for Input text for dates #69
Conversation
Any update on this @RichardLindhout ?? |
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.
@ SantoshVarunk Thanks for your PR I still think some changes are required before we can merge this
if (Number.isNaN(day) || Number.isNaN(year) || Number.isNaN(month)) { | ||
setError(inputFormat) | ||
return | ||
} | ||
|
||
if (month === 0 || month > 12) { | ||
setError('MM should be in range of 1-12') | ||
onChange(undefined) |
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.
I don't think we should change to undefined only show the error
|
||
if (day === 0 || day > monthLength[month - 1]) { | ||
setError('DD should be in range of 1-' + monthLength[month - 1]) | ||
onChange(undefined) |
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.
I don't think we should change to undefined only show the error
@@ -165,11 +176,26 @@ function CalendarInputPure( | |||
const year = Number(date.slice(yearIndex, yearIndex + 4)) | |||
const month = Number(date.slice(monthIndex, monthIndex + 2)) | |||
|
|||
if (year % 400 === 0 || (year % 100 !== 0 && year % 4 === 0)) | |||
monthLength[1] = 29 |
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.
Why 29?
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.
Leap year 29 days. index 1 will be Feb month. Above if conditions is verify if it is leap year.
<Button | ||
color={color} | ||
onPress={props.onSave} | ||
disabled={!props.state.date} |
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.
I don't want to disable buttons, I think the error should be sufficient enough
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.
const [formattedValue, setFormattedValue] = React.useState(null) | ||
const monthLength = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] | ||
|
||
React.useEffect(() => { |
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.
Can we move this to the onChange handler instead of useEffect?
if (Number.isNaN(day) || Number.isNaN(year) || Number.isNaN(month)) { | ||
setError(inputFormat) | ||
return | ||
} | ||
|
||
if (month === 0 || month > 12) { | ||
setError('MM should be in range of 1-12') |
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.
error's should be configurable and be added to examples + readme so users from other countries can configure the right errors
@chakrihacker @SantoshVarunk sorry for my late update, but I now have configurable errors and so per locale so we could move on with this but it needs some changes and use the utils provided in the src/translations/utils |
I'm going to close due to lack of movement. If it is still applicable, please update and we can readdress it. |
closes #66