Skip to content

Make Address element Autocomplete types and country restrictions configurable#46

Open
JosephSaada-optimizely wants to merge 1 commit into
episerver:masterfrom
JosephSaada-optimizely:josephsaada-optimizely-investigate-address-element
Open

Make Address element Autocomplete types and country restrictions configurable#46
JosephSaada-optimizely wants to merge 1 commit into
episerver:masterfrom
JosephSaada-optimizely:josephsaada-optimizely-investigate-address-element

Conversation

@JosephSaada-optimizely

Copy link
Copy Markdown

Problem

The Address form element in EPiServer.Forms.Samples had two limitations:

  • Only showed business/enterprise addresses (hardcoded to types: ['establishment'])
  • No way to restrict results to a specific country
  • Settings could not be changed without code modifications

This prevented forms from accepting residential addresses and working effectively in single-country deployments.

Solution

Added two configurable properties to AddressesElementBlock:

  • AutocompleteTypes (default: "address") - Accepts "address", "establishment", or "address,establishment" to control what address types appear in autocomplete
  • CountryRestriction - Optional ISO country code (e.g., "au", "us") to filter results by country

These settings are passed to the client-side JavaScript via ElementInfo.CustomData and applied directly to the Google Places Autocomplete initialization.

Changes

  • AddressesElementBlock.cs: Added two [Display] properties and updated GetElementInfo() to pass settings to JavaScript
  • AddressesElementBlock.js: Updated Autocomplete initialization to read from element configuration instead of hardcoded values

Impact

  • ✅ Forms can now display residential addresses alongside business addresses
  • ✅ Results can be restricted to a specific country per-form
  • ✅ Content editors can configure without touching code
  • ✅ Supports multiple forms with different settings
  • ✅ Backward compatible (defaults to "address" if not set)

…ss element

- Add AutocompleteTypes property (default: 'address') - supports 'address', 'establishment', or 'address,establishment'
- Add CountryRestriction property (ISO country code, e.g., 'au', 'us')
- Update GetElementInfo() to pass config to client-side JavaScript
- Update AddressesElementBlock.js to read types and country from element config
- Enables editors to configure per-form without code changes

Fixes the issue where Address element only showed business addresses globally.
Now supports residential addresses and country-level filtering.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant