@countriesdb/widget 0.1.27 → 0.1.28

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.
@@ -223,6 +223,27 @@ export async function updateSubdivisionSelect(select, apiKey, backendUrl, state,
223
223
  select.innerHTML += `<option value="${defaultValue}" disabled>Error: No country select present</option>`;
224
224
  }
225
225
  }
226
+ /**
227
+ * Get current subdivision config from window.CountriesDBConfig
228
+ * This ensures we always use the latest config values, even after widget reload
229
+ */
230
+ function getCurrentSubdivisionConfig(apiKey, backendUrl) {
231
+ const globalConfig = typeof window !== 'undefined' && window.CountriesDBConfig
232
+ ? window.CountriesDBConfig
233
+ : null;
234
+ return {
235
+ followRelated: globalConfig?.followRelated || false,
236
+ followUpward: globalConfig?.followUpward || false,
237
+ showSubdivisionType: globalConfig?.showSubdivisionType !== false,
238
+ allowParentSelection: globalConfig?.allowParentSelection || false,
239
+ preferOfficialSubdivisions: globalConfig?.preferOfficialSubdivisions || false,
240
+ subdivisionRomanizationPreference: globalConfig?.subdivisionRomanizationPreference,
241
+ preferLocalVariant: globalConfig?.preferLocalVariant || false,
242
+ forcedLanguage: globalConfig?.forcedLanguage,
243
+ defaultLanguage: globalConfig?.defaultLanguage,
244
+ subdivisionNameFilter: globalConfig?.subdivisionNameFilter,
245
+ };
246
+ }
226
247
  /**
227
248
  * Update subdivisions for all linked subdivision selects when country changes
228
249
  */
@@ -323,8 +344,13 @@ export async function setupCountrySelection(apiKey, backendUrl, state, config, s
323
344
  }
324
345
  // Dispatch update event for user-initiated country change
325
346
  dispatchUpdateEvent(select, { type: 'country', reason: 'regular' });
326
- // Update subdivisions
327
- await updateSubdivisions(select, apiKey, backendUrl, state, subdivisionConfig);
347
+ // Get current config dynamically to ensure we use the latest values
348
+ const currentSubdivisionConfig = getCurrentSubdivisionConfig(apiKey, backendUrl);
349
+ const currentConfig = typeof window !== 'undefined' && window.CountriesDBConfig
350
+ ? window.CountriesDBConfig
351
+ : config;
352
+ // Update subdivisions with current config
353
+ await updateSubdivisions(select, apiKey, backendUrl, state, currentSubdivisionConfig);
328
354
  const chosen = select.value;
329
355
  if (!chosen) {
330
356
  return;
@@ -336,8 +362,9 @@ export async function setupCountrySelection(apiKey, backendUrl, state, config, s
336
362
  }
337
363
  // followUpward from country perspective
338
364
  // Only works when country is single-select (never for multi-select)
339
- if (config.followUpward && !select.multiple && picked.is_subdivision_of) {
340
- await handleFollowUpwardFromCountry(select, apiKey, backendUrl, state, config.followUpward, (s, key, code) => updateSubdivisionSelect(s, key, backendUrl, state, subdivisionConfig, code));
365
+ const currentFollowUpward = currentConfig?.followUpward || false;
366
+ if (currentFollowUpward && !select.multiple && picked.is_subdivision_of) {
367
+ await handleFollowUpwardFromCountry(select, apiKey, backendUrl, state, currentFollowUpward, (s, key, code) => updateSubdivisionSelect(s, key, backendUrl, state, currentSubdivisionConfig, code));
341
368
  }
342
369
  };
343
370
  // Store and attach the handler
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@countriesdb/widget",
3
- "version": "0.1.27",
3
+ "version": "0.1.28",
4
4
  "description": "Country and state/province select widget with ISO 3166-1 and ISO 3166-2 codes. Auto-populates dropdowns with up-to-date country and subdivision data in multiple languages. Easy integration for forms, location selection, and address validation.",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.esm.js",