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

add autoUpperCase rule for alphanumerical postalCode countries #599

Merged
merged 2 commits into from
Jul 29, 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]

### Added
- implemented autoUpperCase rule for countries with alphanumeric postal codes, ensuring consistent uppercase formatting.

## [3.36.6] - 2024-07-23

### Fixed
Expand Down
5 changes: 5 additions & 0 deletions react/AddressContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ class AddressContainer extends Component {
rules.fields &&
rules.fields.find((field) => field.name === 'postalCode')

// Convert postal code to uppercase if autoUpperCase is true
if (postalCodeField && postalCodeField.autoUpperCase) {
changedAddressFields.postalCode.value = changedAddressFields.postalCode.value.toUpperCase()
}

const diffFromPrev =
address.postalCode.value !== validatedAddress.postalCode.value

Expand Down
1 change: 1 addition & 0 deletions react/country/CAN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const rules: PostalCodeRules = {
'https://www.canadapost.ca/cpo/mc/personal/postalcode/fpc.jsf',
size: 'small',
autoComplete: 'nope',
autoUpperCase: true,
},
{
name: 'street',
Expand Down
6 changes: 2 additions & 4 deletions react/country/GBR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const rules: PostalCodeRules = {
postalCodeAPI: false,
size: 'small',
autoComplete: 'nope',
autoUpperCase: true,
},
{
name: 'street',
Expand Down Expand Up @@ -128,10 +129,7 @@ const rules: PostalCodeRules = {

state: {
valueIn: 'long_name',
types: [
'postal_town',
'administrative_area_level_1'
],
types: ['postal_town', 'administrative_area_level_1'],
},

city: {
Expand Down
159 changes: 159 additions & 0 deletions react/country/GIB.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
import { POSTAL_CODE } from '../constants'
import type { PostalCodeRules } from '../types/rules'

const rules: PostalCodeRules = {
country: null,
abbr: null,
postalCodeFrom: POSTAL_CODE,
fields: [
{
hidden: true,
name: 'country',
maxLength: 100,
label: 'country',
size: 'medium',
},
{
name: 'postalCode',
maxLength: 50,
label: 'postalCode',
size: 'small',
autoComplete: 'nope',
postalCodeAPI: false,
autoUpperCase: true,
},
{
name: 'street',
label: 'addressLine1',
required: true,
size: 'xlarge',
},
{
hidden: true,
name: 'number',
maxLength: 750,
label: 'number',
size: 'small',
autoComplete: 'nope',
},
{
name: 'complement',
maxLength: 750,
label: 'addressLine2',
size: 'xlarge',
},
{
hidden: true,
name: 'reference',
maxLength: 750,
label: 'reference',
size: 'xlarge',
},
{
hidden: true,
name: 'neighborhood',
maxLength: 100,
label: 'neighborhood',
size: 'large',
},
{
name: 'city',
maxLength: 100,
label: 'city',
required: true,
size: 'large',
},
{
name: 'state',
maxLength: 100,
label: 'state',
required: true,
size: 'large',
},
{
name: 'receiverName',
elementName: 'receiver',
maxLength: 750,
label: 'receiverName',
size: 'xlarge',
required: true,
},
],
geolocation: {
postalCode: {
valueIn: 'long_name',
types: ['postal_code'],
required: false,
},

number: {
valueIn: 'long_name',
types: ['street_number'],
required: false,
notApplicable: true,
},

street: { valueIn: 'long_name', types: ['route'] },

neighborhood: {
valueIn: 'long_name',
types: [
'neighborhood',
'sublocality_level_1',
'sublocality_level_2',
'sublocality_level_3',
'sublocality_level_4',
'sublocality_level_5',
],
},

state: {
valueIn: 'long_name',
types: ['administrative_area_level_1'],
},

city: {
valueIn: 'long_name',
types: ['administrative_area_level_2', 'locality'],
},

receiverName: {
required: true,
},
},
summary: [
[
{
name: 'street',
},
{
delimiter: ' ',
name: 'number',
},
{
delimiter: ', ',
name: 'complement',
},
],
[
{
name: 'neighborhood',
delimiterAfter: ' - ',
},
{
name: 'city',
},
{
delimiter: ' - ',
name: 'state',
},
],
[
{
name: 'postalCode',
},
],
],
}

export default rules
1 change: 1 addition & 0 deletions react/country/IRL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const rules: PostalCodeRules = {
postalCodeAPI: true,
size: 'small',
autoComplete: 'nope',
autoUpperCase: true,
},
{
name: 'street',
Expand Down
159 changes: 159 additions & 0 deletions react/country/LTU.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
import { POSTAL_CODE } from '../constants'
import type { PostalCodeRules } from '../types/rules'

const rules: PostalCodeRules = {
country: null,
abbr: null,
postalCodeFrom: POSTAL_CODE,
fields: [
{
hidden: true,
name: 'country',
maxLength: 100,
label: 'country',
size: 'medium',
},
{
name: 'postalCode',
maxLength: 50,
label: 'postalCode',
size: 'small',
autoComplete: 'nope',
postalCodeAPI: false,
autoUpperCase: true,
},
{
name: 'street',
label: 'addressLine1',
required: true,
size: 'xlarge',
},
{
hidden: true,
name: 'number',
maxLength: 750,
label: 'number',
size: 'small',
autoComplete: 'nope',
},
{
name: 'complement',
maxLength: 750,
label: 'addressLine2',
size: 'xlarge',
},
{
hidden: true,
name: 'reference',
maxLength: 750,
label: 'reference',
size: 'xlarge',
},
{
hidden: true,
name: 'neighborhood',
maxLength: 100,
label: 'neighborhood',
size: 'large',
},
{
name: 'city',
maxLength: 100,
label: 'city',
required: true,
size: 'large',
},
{
name: 'state',
maxLength: 100,
label: 'state',
required: true,
size: 'large',
},
{
name: 'receiverName',
elementName: 'receiver',
maxLength: 750,
label: 'receiverName',
size: 'xlarge',
required: true,
},
],
geolocation: {
postalCode: {
valueIn: 'long_name',
types: ['postal_code'],
required: false,
},

number: {
valueIn: 'long_name',
types: ['street_number'],
required: false,
notApplicable: true,
},

street: { valueIn: 'long_name', types: ['route'] },

neighborhood: {
valueIn: 'long_name',
types: [
'neighborhood',
'sublocality_level_1',
'sublocality_level_2',
'sublocality_level_3',
'sublocality_level_4',
'sublocality_level_5',
],
},

state: {
valueIn: 'long_name',
types: ['administrative_area_level_1'],
},

city: {
valueIn: 'long_name',
types: ['administrative_area_level_2', 'locality'],
},

receiverName: {
required: true,
},
},
summary: [
[
{
name: 'street',
},
{
delimiter: ' ',
name: 'number',
},
{
delimiter: ', ',
name: 'complement',
},
],
[
{
name: 'neighborhood',
delimiterAfter: ' - ',
},
{
name: 'city',
},
{
delimiter: ' - ',
name: 'state',
},
],
[
{
name: 'postalCode',
},
],
],
}

export default rules
Loading
Loading