ArnoldV/Our.Umbraco.GMaps

Prevent address values from being format to all lowercase in views ?

frederiquefortier opened this issue · 11 comments

Hi, I really like this plugin, but I have one small issue I didn't managed to fix :

When selecting a address from the autocomplete feature, it show up as expected in the backoffice, but once I'm in my view, the initial formatting is lost and everything is in lowercase. At the beginning, I thought it was because of how the information is keep in memory, but if I changed the gmaps property type to a rich text editor, I can see that the data in memory has the uppercases and lowercase at the accurate location in the string.

Example in backoffice rich text editor:
image

Example once print in my view :
image

I can't simply capitalize myself since in some address, I'll have a string like this : "54 Côte du Palais", where I want one word to stay in lowercase. At the moment, my solution is to add another property where my users can enter the full street address in the formatting they want, but since I know the info is already there with the plugin, I would prefer to use it.

Would it be possible to fixed this please?

Thanks you!

Hi @frederiquefortier it's very unlikely to be an issue with the data stored - as you say, it's already capitalised. It's more likely to be the formatting you're applying at the front end with CSS or similar...

Hi, thanks for the fast answer! I tried removing all my styles & it's still show up like that. If I go into the debugger of my editor, I can also confirm the data is already in lowercase :
image

Hm. That's very odd - there's nothing in the code to actually transform it all to lowercase...

I'm quite confuse myself.

I realized I forgot to mention my Umbraco version, it's version 10.7.0. I don't know if it can be link (I'm frankly not that great at backend), but my website is also bilingual.

What version of the plugin do you have installed? Not that it should matter, there's nothing there to transform as I said...

The latest one, version 2.1.3.

image

can you share the code you are using to retrieve the property value?

Sure, here it is:

@using [ProjetName].Site.Extensions
@inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage<[ProjetName].Site.UmbracoModels.Restaurant>

@{
    var mapAddress = Model.RestaurantMapPosition?.Address;
}

<div class="js-map-restaurant"
     data-key="@Model.Key"
     data-name="@Model.RestaurantName"
     data-lat="@mapAddress?.Coordinates.Latitude"
     data-lng="@mapAddress?.Coordinates.Longitude">

    <div class="restaurant">
        <div class="rte">
            @*At the moment, I'm using this rte as an alternative; if empty, I still show the address as is return by plugin*@
            @if (!string.IsNullOrWhiteSpace(Model.RestaurantAddress?.ToString()))
            {
                @Model.RestaurantAddress
            }
            else if (mapAddress != null)
            {
                <p>@mapAddress.StreetNumber @mapAddress.Street</p>
                <p>@mapAddress.City (@mapAddress.State) @mapAddress.PostalCode</p>
            }
        </div>

           
    </div>
</div>

In my appsettings, to configure the plugin, I have this:

  "GoogleMaps": {
    "ApiKey": "[myKey]",
    "DefaultLocation": "46.81333846653875, -71.23231629758057"
  }

And in Umbraco, I created the datatype with those settings :
image

It show up without any error :
image

@robertjf I believe this issue is caused by line 36 of the SingleMapPropertyValueConverter, which lowercases the JSON before it is deserialised, in order to perform .Replace and .Contains first:

  // Handle pre v2.0.0 data.
inter = inter.ToString().ToLower().Replace("google.maps.maptypeid.", string.Empty);
bool legacyData = inter.ToString().Contains("latlng");

I have found that if the ToLower() on line 36 is removed, this issue is resolved. In order to maintain the functionality of the .Replace and .Contains usages, may I suggest:

  • Removing the use of .Replace("google.maps.maptypeid.", string.Empty, as the models this JSON is deserialised to lack this property, so it will be discarded on deserialisation anyway
  • Running ToLower() on the legacyData check itself, without modifying the value of inter, eg bool legacyData = inter.ToString().ToLower().Contains("latlng")

@robertjf would it be ok to update the package per @Jonty-Schmidt's suggestions?

Thanks again for a great package.

@ArnoldV @robertjf

I can confirm this is an issue with the Property Value Convertor code as mentioned by @Jonty-Schmidt and this had my head scratching for a while to figure out why it was coming out lowercase, when Examine and the DB stores the address in the correct casing.

Here is the Umbraco HQ address that renders out in lowercase when rendered out on the frontend

image

And here it is in Examine storing the JSON value correctly without the address being lowercased

image

I will submit a PR shortly to fix this and will probably take @Jonty-Schmidt suggestion as the fix.