-
Notifications
You must be signed in to change notification settings - Fork 3k
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
fix: constrain min and max age date for dob pickers #17072
Changes from all commits
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 |
---|---|---|
|
@@ -63,6 +63,7 @@ const CONST = { | |
|
||
DATE_BIRTH: { | ||
MIN_AGE: 5, | ||
MIN_AGE_FOR_PAYMENT: 18, | ||
MAX_AGE: 150, | ||
}, | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ import React from 'react'; | |
import PropTypes from 'prop-types'; | ||
import {withOnyx} from 'react-native-onyx'; | ||
import {View} from 'react-native'; | ||
import moment from 'moment/moment'; | ||
import IdologyQuestions from './IdologyQuestions'; | ||
import ScreenWrapper from '../../components/ScreenWrapper'; | ||
import HeaderWithCloseButton from '../../components/HeaderWithCloseButton'; | ||
|
@@ -108,6 +109,9 @@ class AdditionalDetailsStep extends React.Component { | |
ssn: 'common.ssnLast4', | ||
ssnFull9: 'common.ssnFull9', | ||
}; | ||
|
||
this.minDate = moment().subtract(CONST.DATE_BIRTH.MAX_AGE, 'Y').toDate(); | ||
this.maxDate = moment().subtract(CONST.DATE_BIRTH.MIN_AGE_FOR_PAYMENT, 'Y').toDate(); | ||
Comment on lines
+113
to
+114
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. 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. NAB, since they're one-liners and I'm not going to lose sleep over it. But since you bring it up, maybe it makes more sense to put the logic in the DatePicker component since both pages use it. |
||
} | ||
|
||
/** | ||
|
@@ -262,6 +266,8 @@ class AdditionalDetailsStep extends React.Component { | |
containerStyles={[styles.mt4]} | ||
label={this.props.translate(this.fieldNameTranslationKeys.dob)} | ||
placeholder={this.props.translate('common.dob')} | ||
minDate={this.minDate} | ||
maxDate={this.maxDate} | ||
shouldSaveDraft | ||
/> | ||
<TextInput | ||
|
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 do we need to format it here?
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.
For min and max attribute input type="date" accepts a formatted string (yyyy-mm-dd). We pass the prop in Date format, so it needs to be formatted to work properly. We do the same for the value and the defaultValue.