@@ -52,7 +52,7 @@ class GoogleMapField extends CompositeField
52
52
/**
53
53
* @var TextField
54
54
*/
55
- protected $ searchBox ;
55
+ protected $ searchField ;
56
56
57
57
/**
58
58
* The merged version of the default and user specified options
@@ -87,28 +87,26 @@ public function setDataRecord($data)
87
87
}
88
88
89
89
90
- public function setValue ( $ value , $ data = null )
90
+ public function hasData ( )
91
91
{
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
+ }
103
94
104
- $ this ->boundsField ->setValue (
105
- $ value ['Bounds ' ]
106
- );
107
95
96
+ public function setValue ($ value , $ data = null )
97
+ {
108
98
if ($ data ) {
109
99
$ this ->setDataRecord ($ data );
100
+ } else if (!$ this ->children ->count ()) {
101
+ $ this ->setupChildren ();
110
102
}
111
103
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
+
112
110
return parent ::setValue ($ value , $ data );
113
111
}
114
112
@@ -178,12 +176,12 @@ public function setupChildren()
178
176
$ this ->children ->push ($ this ->zoomField );
179
177
$ this ->children ->push ($ this ->boundsField );
180
178
181
- $ this ->searchBox = TextField::create ($ name . '[Search] ' , $ this ->Title , $ this ->recordFieldData ('Search ' ))
179
+ $ this ->searchField = TextField::create ($ name . '[Search] ' , $ this ->Title , $ this ->recordFieldData ('Search ' ))
182
180
->addExtraClass ('googlemapfield-searchfield ' )
183
181
->setAttribute ('placeholder ' , 'Search for a location ' );
184
182
185
183
if ($ this ->options ['show_search_box ' ]) {
186
- $ this ->children ->push ($ this ->searchBox );
184
+ $ this ->children ->push ($ this ->searchField );
187
185
}
188
186
189
187
return $ this ;
0 commit comments