Skip to content
This repository has been archived by the owner on Jul 27, 2021. It is now read-only.

Commit

Permalink
BUG Fix changes being detected on value initialisation
Browse files Browse the repository at this point in the history
  • Loading branch information
Luke Edwards committed Sep 18, 2018
1 parent a8e3683 commit f0e22c3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
14 changes: 9 additions & 5 deletions client/js/GoogleMapField.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,22 @@

latField.val(latCoord);
lngField.val(lngCoord);
updateBounds();
updateBounds(init);

// Mark form as changed if this isn't initialisation
if (!init) {
// Mark as changed(?)
$('.cms-edit-form').addClass('changed');
}
}

function updateZoom() {
function updateZoom(init) {
zoomField.val(map.getZoom());
// Mark form as changed if this isn't initialisation
if (!init) {
$('.cms-edit-form').addClass('changed');
}
}

function updateBounds() {
var bounds = JSON.stringify(map.getBounds().toJSON());
boundsField.val(bounds);
Expand Down Expand Up @@ -101,7 +105,7 @@
// Populate the fields to the current centre
google.maps.event.addListenerOnce(map, 'idle', function(){
updateField(map.getCenter(), true);
updateZoom();
updateZoom(init);
});

google.maps.event.addListener(marker, 'dragend', centreOnMarker);
Expand Down
8 changes: 4 additions & 4 deletions src/GoogleMapField.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,24 +108,24 @@ public function setupChildren() {
$name.'[Latitude]',
'Lat',
$this->recordFieldData('Latitude')
)->addExtraClass('googlemapfield-latfield');
)->addExtraClass('googlemapfield-latfield no-detect-changes');

$this->lngField = HiddenField::create(
$name.'[Longitude]',
'Lng',
$this->recordFieldData('Longitude')
)->addExtraClass('googlemapfield-lngfield');
)->addExtraClass('googlemapfield-lngfield no-detect-changes');

$this->zoomField = HiddenField::create(
$name.'[Zoom]',
'Zoom',
$this->recordFieldData('Zoom')
)->addExtraClass('googlemapfield-zoomfield');
)->addExtraClass('googlemapfield-zoomfield no-detect-changes');
$this->boundsField = HiddenField::create(
$name.'[Bounds]',
'Bounds',
$this->recordFieldData('Bounds')
)->addExtraClass('googlemapfield-boundsfield');
)->addExtraClass('googlemapfield-boundsfield no-detect-changes');
$this->children = new FieldList(
$this->latField,
$this->lngField,
Expand Down

0 comments on commit f0e22c3

Please sign in to comment.