@abgov/jsonforms-components 2.4.2 → 2.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.esm.js CHANGED
@@ -9623,6 +9623,22 @@ const formatPostalCode = value => {
9623
9623
  }
9624
9624
  return value;
9625
9625
  };
9626
+ function detectPostalCodeType(input) {
9627
+ const cleaned = input.toUpperCase().replace(/[^A-Z0-9]/g, '');
9628
+ const fullPostal = /^[A-Z]\d[A-Z]\d[A-Z]\d$/;
9629
+ const partialPostal = /^[A-Z]\d[A-Z]?\d?[A-Z]?\d?$/;
9630
+ if (fullPostal.test(cleaned)) return 'full';
9631
+ if (partialPostal.test(cleaned)) return 'partial';
9632
+ return 'none';
9633
+ }
9634
+ function formatPostalCodeIfNeeded(input) {
9635
+ const cleaned = input.trim().toUpperCase().replace(/[^A-Z0-9]/g, '');
9636
+ const type = detectPostalCodeType(cleaned);
9637
+ if (type === 'none') return input;
9638
+ const before = cleaned.slice(0, 3);
9639
+ const after = cleaned.slice(3);
9640
+ return `${before} ${after}`;
9641
+ }
9626
9642
 
9627
9643
  let _ = t => t,
9628
9644
  _t,
@@ -9966,7 +9982,7 @@ const AddressLookUpControl = props => {
9966
9982
  if (searchTerm.length > 2 && dropdownSelected === false) {
9967
9983
  setLoading(true);
9968
9984
  setOpen(true);
9969
- yield fetchAddressSuggestions(formUrl, searchTerm, isAlbertaAddress).then(response => {
9985
+ yield fetchAddressSuggestions(formUrl, formatPostalCodeIfNeeded(searchTerm), isAlbertaAddress).then(response => {
9970
9986
  const suggestions = filterSuggestionsWithoutAddressCount(response);
9971
9987
  if (isAlbertaAddress) {
9972
9988
  setSuggestions(filterAlbertaAddresses(suggestions));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abgov/jsonforms-components",
3
- "version": "2.4.2",
3
+ "version": "2.4.3",
4
4
  "license": "Apache-2.0",
5
5
  "description": "Government of Alberta - React renderers for JSON Forms based on the design system.",
6
6
  "repository": "https://github.com/GovAlta/adsp-monorepo",
@@ -8,3 +8,5 @@ export declare const handlePostalCodeValidation: (validatePc: boolean, message:
8
8
  [x: string]: string;
9
9
  };
10
10
  export declare const formatPostalCode: (value: string) => string;
11
+ export declare function detectPostalCodeType(input: string): 'full' | 'partial' | 'none';
12
+ export declare function formatPostalCodeIfNeeded(input: string): string;