Skip to content
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

Closed
wants to merge 2 commits into from

Conversation

SantoshVarunk
Copy link

@SantoshVarunk SantoshVarunk commented Apr 12, 2021

closes #66

@chakrihacker
Copy link
Contributor

Any update on this @RichardLindhout ??

Copy link
Member

@RichardLindhout RichardLindhout left a 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)
Copy link
Member

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)
Copy link
Member

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why 29?

Copy link
Author

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}
Copy link
Member

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

Copy link
Member

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(() => {
Copy link
Member

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')
Copy link
Member

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

@RichardLindhout
Copy link
Member

@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

@iM-GeeKy
Copy link
Collaborator

I'm going to close due to lack of movement. If it is still applicable, please update and we can readdress it.

@iM-GeeKy iM-GeeKy closed this Sep 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Accepting invalid DATE, YEAR while in text mode and returning last selected date.
4 participants