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

update rules + shouldShowNumberKeyboard logic #610

Merged
merged 1 commit into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

### Fixed
- Logic to validate if a country should use Number Keyboard (shouldShowNumberKeyboard).

## [4.24.7] - 2024-08-30

### Added
Expand Down
9 changes: 6 additions & 3 deletions react/PostalCodeGetter.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,12 @@ class PostalCodeGetter extends Component {
default:
case POSTAL_CODE: {
const field = getField('postalCode', rules)
const shouldShowNumberKeyboard = !Number.isNaN(
removeNonWords(field.mask)
)
const numericString = field.mask ? removeNonWords(field.mask) : ''
const isPurelyNumeric =
numericString === '' || /^\d+$/.test(numericString)
const shouldShowNumberKeyboard = isNaN(field.mask)
? isPurelyNumeric
: false

return (
<InputFieldContainer
Expand Down
3 changes: 2 additions & 1 deletion react/country/GBR.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ export default {
maxLength: 50,
fixedLabel: 'Postcode',
required: true,
mask: '',
// UK has different patterns for postal codes alphanumericals, so we need can't use a mask.
mask: NaN,
regex: /^([A-Za-z][A-Ha-hJ-Yj-y]?[0-9][A-Za-z0-9]? ?[0-9][A-Za-z]{2}|[Gg][Ii][Rr] ?0[Aa]{2})$/,
postalCodeAPI: false,
size: 'small',
Expand Down
2 changes: 1 addition & 1 deletion react/country/IRL.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default {
maxLength: 8,
label: 'postalCode',
required: true,
mask: '999 9999',
mask: 'A99 A9A9',
regex: /(?:^[AC-FHKNPRTV-Y][0-9]{2}|D6W)[ -]?[0-9AC-FHKNPRTV-Y]{4}$/,
postalCodeAPI: true,
size: 'small',
Expand Down
Loading