novo-elements 13.7.1-next.1 → 13.7.1

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.
@@ -1004,6 +1004,7 @@ interface AddressLookupResult {
1004
1004
  address2?: string;
1005
1005
  city?: string;
1006
1006
  state?: string;
1007
+ stateName?: string;
1007
1008
  zip?: string;
1008
1009
  countryName?: string;
1009
1010
  countryCode?: string;
@@ -1093,9 +1094,10 @@ declare class NovoAddressElement implements ControlValueAccessor, OnInit, DoChec
1093
1094
  address_components?: any[];
1094
1095
  formatted_address?: string;
1095
1096
  }): void;
1097
+ private resolveStateValue;
1096
1098
  private parseGooglePlaceDetail;
1097
1099
  setStateLabel(model: any): void;
1098
- updateStates(): void;
1100
+ updateStates(): Promise<any[]>;
1099
1101
  getStateOptions(filter: string, countryID: number): string[];
1100
1102
  updateControl(): void;
1101
1103
  writeValue(model: any): void;
@@ -3971,9 +3971,6 @@ class NovoAddressElement {
3971
3971
  if (result.city !== undefined) {
3972
3972
  this.model.city = result.city;
3973
3973
  }
3974
- if (result.state !== undefined) {
3975
- this.model.state = result.state;
3976
- }
3977
3974
  if (result.zip !== undefined) {
3978
3975
  this.model.zip = result.zip;
3979
3976
  }
@@ -3984,11 +3981,32 @@ class NovoAddressElement {
3984
3981
  this.model.countryName = country.name;
3985
3982
  }
3986
3983
  }
3987
- this.updateStates();
3988
- this.updateControl();
3989
- this.fieldList.forEach((field) => this.onInput(null, field));
3990
3984
  this.debouncedSearch = '';
3991
3985
  this.overlay?.closePanel();
3986
+ // State values differ by picker (name, code or id), so resolve against the loaded options before emitting.
3987
+ this.updateStates()
3988
+ .catch(() => [])
3989
+ .then((stateOptions) => {
3990
+ if (result.state !== undefined || result.stateName !== undefined) {
3991
+ this.model.state = this.resolveStateValue(stateOptions, result);
3992
+ }
3993
+ this.updateControl();
3994
+ this.fieldList.forEach((field) => this.onInput(null, field));
3995
+ });
3996
+ }
3997
+ // Store what a manual pick of the same state would store (option[pickerConfig.field]).
3998
+ resolveStateValue(stateOptions, { state, stateName }) {
3999
+ const name = stateName?.trim().toLowerCase();
4000
+ const code = state?.trim().toLowerCase();
4001
+ const match = stateOptions.find((option) => {
4002
+ const label = String(option?.label ?? option).toLowerCase();
4003
+ const value = String(option?.value ?? option).toLowerCase();
4004
+ return label === name || value === code;
4005
+ });
4006
+ if (match === undefined) {
4007
+ return stateName || state;
4008
+ }
4009
+ return typeof match === 'string' ? match : match[this.config.state.pickerConfig.field ?? 'value'];
3992
4010
  }
3993
4011
  // Map a raw Google detail to flat fields; omitted components resolve to '' so partial selections clear finer fields.
3994
4012
  parseGooglePlaceDetail(place) {
@@ -4005,7 +4023,8 @@ class NovoAddressElement {
4005
4023
  address1: street,
4006
4024
  address2: find('subpremise'),
4007
4025
  city: find('locality') || find('postal_town') || find('sublocality') || find('sublocality_level_1'),
4008
- state: find('administrative_area_level_1'),
4026
+ state: find('administrative_area_level_1', true),
4027
+ stateName: find('administrative_area_level_1'),
4009
4028
  zip: find('postal_code'),
4010
4029
  countryName: find('country'),
4011
4030
  countryCode: find('country', true),
@@ -4033,7 +4052,7 @@ class NovoAddressElement {
4033
4052
  this.config.state.pickerConfig.options = (query = '') => {
4034
4053
  return this.stateOptions(query, this.model.countryID);
4035
4054
  };
4036
- this.stateOptions('', this.model.countryID).then((results) => {
4055
+ return this.stateOptions('', this.model.countryID).then((results) => {
4037
4056
  this.config.state.pickerConfig.defaultOptions = results;
4038
4057
  if (results.length) {
4039
4058
  this.tooltip.state = undefined;
@@ -4049,6 +4068,7 @@ class NovoAddressElement {
4049
4068
  }
4050
4069
  this.validityChange.emit();
4051
4070
  this.onInput(null, 'state');
4071
+ return results;
4052
4072
  });
4053
4073
  }
4054
4074
  else {
@@ -4058,6 +4078,7 @@ class NovoAddressElement {
4058
4078
  if (this.config.state.required) {
4059
4079
  this.valid.state = false;
4060
4080
  }
4081
+ return Promise.resolve([]);
4061
4082
  }
4062
4083
  }
4063
4084
  getStateOptions(filter = '', countryID) {