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; }