From 2718be1bdd499cc2c2d6ffee73fd44edba5ef147 Mon Sep 17 00:00:00 2001 From: Joseph Saada Date: Fri, 10 Jul 2026 10:25:57 -0700 Subject: [PATCH] Add configurable Autocomplete types and country restrictions to Address 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> --- .../ViewMode/js/AddressesElementBlock.js | 10 +++++++++- .../Elements/AddressesElementBlock.cs | 14 ++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/EPiServer.Forms.Samples/ClientResources/ViewMode/js/AddressesElementBlock.js b/src/EPiServer.Forms.Samples/ClientResources/ViewMode/js/AddressesElementBlock.js index 4b700b9..5f65f23 100644 --- a/src/EPiServer.Forms.Samples/ClientResources/ViewMode/js/AddressesElementBlock.js +++ b/src/EPiServer.Forms.Samples/ClientResources/ViewMode/js/AddressesElementBlock.js @@ -31,9 +31,17 @@ if (!google || !google.maps.places) { return; } + + // Read configuration from element info + var types = (addressElementInfo.customData?.autocompleteTypes || 'address').split(',').map(t => t.trim()); var options = { - types: ['establishment'] + types: types }; + + // Add country restriction if configured + if (addressElementInfo.customData?.countryRestriction) { + options.componentRestrictions = { country: addressElementInfo.customData.countryRestriction }; + } var gPlace = new google.maps.places.Autocomplete(addressEl[0], options); google.maps.event.addListener(gPlace, 'place_changed', function () { diff --git a/src/EPiServer.Forms.Samples/Implementation/Elements/AddressesElementBlock.cs b/src/EPiServer.Forms.Samples/Implementation/Elements/AddressesElementBlock.cs index aeb2072..8428687 100644 --- a/src/EPiServer.Forms.Samples/Implementation/Elements/AddressesElementBlock.cs +++ b/src/EPiServer.Forms.Samples/Implementation/Elements/AddressesElementBlock.cs @@ -100,6 +100,15 @@ public virtual string ApiKey [Display(GroupName = SystemTabNames.Content, Order = -6800)] public virtual string CountryLabel { get; set; } + [Display(GroupName = SystemTabNames.Content, Order = -6250)] + [UIHint(UIHint.Textarea)] + public virtual string AutocompleteTypes { get; set; } = "address"; + // Options: "address", "establishment", or "address,establishment" + + [Display(GroupName = SystemTabNames.Content, Order = -6260)] + public virtual string CountryRestriction { get; set; } + // ISO country code (e.g., "au" for Australia, "us" for USA) + /// /// Always use AddressValidator to validate this element /// hide from EditView @@ -188,6 +197,11 @@ public override ElementInfo GetElementInfo() { var baseInfo = base.GetElementInfo(); baseInfo.CustomBinding = true; + baseInfo.CustomData = new Dictionary + { + { "autocompleteTypes", AutocompleteTypes ?? "address" }, + { "countryRestriction", CountryRestriction } + }; return baseInfo; }