Skip to content

Commit 13ec222

Browse files
committed
fix: setValue not saving from record
1 parent 3e3b653 commit 13ec222

File tree

1 file changed

+16
-18
lines changed

1 file changed

+16
-18
lines changed

src/GoogleMapField.php

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class GoogleMapField extends CompositeField
5252
/**
5353
* @var TextField
5454
*/
55-
protected $searchBox;
55+
protected $searchField;
5656

5757
/**
5858
* The merged version of the default and user specified options
@@ -87,28 +87,26 @@ public function setDataRecord($data)
8787
}
8888

8989

90-
public function setValue($value, $data = null)
90+
public function hasData()
9191
{
92-
$this->latField->setValue(
93-
$value['Latitude']
94-
);
95-
96-
$this->lngField->setValue(
97-
$value['Longitude']
98-
);
99-
100-
$this->zoomField->setValue(
101-
$value['Zoom']
102-
);
92+
return true;
93+
}
10394

104-
$this->boundsField->setValue(
105-
$value['Bounds']
106-
);
10795

96+
public function setValue($value, $data = null)
97+
{
10898
if ($data) {
10999
$this->setDataRecord($data);
100+
} else if (!$this->children->count()) {
101+
$this->setupChildren();
110102
}
111103

104+
$this->latField->setValue($value['Latitude'] ?? '', $data);
105+
$this->lngField->setValue($value['Longitude'] ?? '', $data);
106+
$this->zoomField->setValue($value['Zoom'] ?? '', $data);
107+
$this->boundsField->setValue($value['Bounds'] ?? '', $data);
108+
$this->searchField->setValue($value['Search'] ?? '', $data);
109+
112110
return parent::setValue($value, $data);
113111
}
114112

@@ -178,12 +176,12 @@ public function setupChildren()
178176
$this->children->push($this->zoomField);
179177
$this->children->push($this->boundsField);
180178

181-
$this->searchBox = TextField::create($name . '[Search]', $this->Title, $this->recordFieldData('Search'))
179+
$this->searchField = TextField::create($name . '[Search]', $this->Title, $this->recordFieldData('Search'))
182180
->addExtraClass('googlemapfield-searchfield')
183181
->setAttribute('placeholder', 'Search for a location');
184182

185183
if ($this->options['show_search_box']) {
186-
$this->children->push($this->searchBox);
184+
$this->children->push($this->searchField);
187185
}
188186

189187
return $this;

0 commit comments

Comments
 (0)