Skip to content

Commit 552b704

Browse files
authored
Merge pull request #3 from tedgustaf/hotfix-clear-coordinates
Change event when clearing local block coordinates
2 parents 217d29c + c4ceebf commit 552b704

File tree

2 files changed

+37
-22
lines changed

2 files changed

+37
-22
lines changed

GoogleMapsEditor/ClientResources/googlemaps/Editor.js

Lines changed: 35 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,23 @@ function (
4141
// Help dialog displayed when clicking the question mark icon
4242
_helpDialog: null,
4343

44+
_logPrefix: "[GoogleMapsEditor]",
45+
4446
templateString: template,
4547

4648
_setValueAttr: function (/*anything*/ newValue, /*Boolean?*/ priorityChange) {
4749
this.inherited(arguments);
4850

49-
this.textbox.value = newValue;
51+
this.textbox.value = newValue || "";
5052

5153
if (this._marker == null) // Initial load
5254
{
5355
this._refreshMarkerLocation();
5456
}
57+
58+
if (this._isComplexType()) {
59+
this.onChange(newValue); // Otherwise onChange won't trigger correctly for complex property types
60+
}
5561
},
5662

5763
/**
@@ -138,7 +144,7 @@ function (
138144
}
139145

140146
// Clear the property value
141-
this.set("value", null);
147+
this._setCoordinatesValue(null);
142148
},
143149

144150
/**
@@ -190,7 +196,7 @@ function (
190196
return;
191197
}
192198

193-
const messageWithPrefix = `[GoogleMapsEditor] ${message}`;
199+
const messageWithPrefix = `${this._logPrefix} ${message}`;
194200

195201
if (data) {
196202
console.log(messageWithPrefix, data);
@@ -331,30 +337,39 @@ function (
331337
return;
332338
}
333339

334-
const longitude = location.lng(),
335-
latitude = location.lat();
340+
let value = null;
336341

337-
if (longitude === undefined || latitude === undefined) {
338-
return;
342+
if (!location) {
343+
if (this._isComplexType()) {
344+
// Set "empty" value (still an object for local block properties)
345+
value = {
346+
"latitude": null,
347+
"longitude": null
348+
};
349+
}
339350
}
351+
else { // Has a location
352+
const longitude = location.lng(),
353+
latitude = location.lat();
340354

341-
// Get the new value in the correct format
342-
let value;
343-
if (this._isComplexType()) {
344-
value = {
345-
"latitude": parseFloat(latitude),
346-
"longitude": parseFloat(longitude)
347-
};
348-
} else {
349-
value = latitude + "," + longitude;
355+
if (longitude === undefined || latitude === undefined) {
356+
console.error(`${this._logPrefix} Unexpectedly missing longitude and/or latitude coordinate`);
357+
return;
358+
}
359+
360+
// Get the new value in the correct format
361+
if (this._isComplexType()) {
362+
value = {
363+
"latitude": parseFloat(latitude),
364+
"longitude": parseFloat(longitude)
365+
};
366+
} else {
367+
value = latitude + "," + longitude;
368+
}
350369
}
351370

352371
// Set the widget (i.e. property) value and trigger change event to notify the CMS (and possibly others) that the value has changed
353372
this.set("value", value);
354-
355-
if (this._isComplexType()) {
356-
this.onChange(value); // Otherwise onChange won't trigger correctly for complex property types
357-
}
358373
},
359374

360375
/**

GoogleMapsEditor/GoogleMapsEditor.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<ImplicitUsings>disable</ImplicitUsings>
88
<OutputType>Library</OutputType>
99
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
10-
<FileVersion>4.0.0.2</FileVersion>
10+
<FileVersion>4.0.0.3</FileVersion>
1111
<InformationalVersion>Optimizely CMS 12</InformationalVersion>
1212
<Title>Google Maps Editor for Optimizely</Title>
1313
<Description>Editor for setting coordinates using Google Maps.</Description>
@@ -31,7 +31,7 @@
3131
<PackageLicenseFile>LICENSE</PackageLicenseFile>
3232
<PackageRequireLicenseAcceptance>True</PackageRequireLicenseAcceptance>
3333
<PackageReadmeFile>readme.md</PackageReadmeFile>
34-
<PackageReleaseNotes>Fixed bug where marker would not be displayed for block instances inside IList&lt;TBlock&gt; properties.</PackageReleaseNotes>
34+
<PackageReleaseNotes>Fixed bug where change event would not trigger when clearing coordinates for local block properties.</PackageReleaseNotes>
3535
<PackageTags>Optimizely</PackageTags>
3636
</PropertyGroup>
3737

0 commit comments

Comments
 (0)