-
Notifications
You must be signed in to change notification settings - Fork 9
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
CreditCardNumber field should report cardType #189
Changes from 1 commit
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 |
---|---|---|
|
@@ -43,7 +43,7 @@ export default class CreditCardNumber extends Component { | |
setValue = (proposedValue) => { | ||
let value = proposedValue.replace(/[^0-9]/g, ''); | ||
if (proposedValue === '') { | ||
this.props.onChange(value, false); | ||
this.props.onChange(value, false, undefined); | ||
this.setState({ value, cardType: undefined }); | ||
return; | ||
} | ||
|
@@ -71,7 +71,7 @@ export default class CreditCardNumber extends Component { | |
|
||
// Only accept the change if we recognize the card type, and it is/may be valid | ||
if (!this.props.restrictInput || cardType && (isValid || isPotentiallyValid)) { | ||
this.props.onChange(value, isValid); | ||
this.props.onChange(value, isValid, card.type); | ||
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. If 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. They are not the same. |
||
this.setState({ value, cardType, isValid }); | ||
} | ||
} | ||
|
@@ -103,7 +103,7 @@ CreditCardNumber.defaultProps = { | |
restrictInput: false, | ||
value: '', | ||
|
||
onChange: (cardNumber, isValid) => true, // eslint-disable-line no-unused-vars | ||
onChange: (cardNumber, isValid, cardType) => true, // eslint-disable-line no-unused-vars | ||
}; | ||
CreditCardNumber.propTypes = { | ||
allowedBrands: PropTypes.arrayOf(PropTypes.string), | ||
|
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.
Unrelated toI'm thinking this parsing logic might be better outside of the React component - can we make separate JS file in react-gears for this? Would be easier to test and update too.
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.
The parsing logic is already outside the component - it's handled by an external lib. I'm also reticent to refactor just for refactoring sake - is there a use-case that the current implementation doesn't support?