@@ -44,6 +44,10 @@ class AddressFinderField extends TextField
44
44
45
45
private static $ include_address_finder_js = true ;
46
46
47
+ private $ showLatLngManual = false ;
48
+
49
+ private $ requireLatLngManual = false ;
50
+
47
51
/**
48
52
* @param string $name
49
53
* @param string $title
@@ -95,6 +99,21 @@ public function __construct($name, $title = null, $value = null)
95
99
parent ::__construct ($ name , $ title , $ value );
96
100
}
97
101
102
+ public function setShowLatLngManual ($ bool )
103
+ {
104
+ $ this ->showLatLngManual = $ bool ;
105
+
106
+ return $ this ;
107
+ }
108
+
109
+ public function setRequireLatLngManual ($ bool )
110
+ {
111
+ $ this ->requireLatLngManual = $ bool ;
112
+
113
+ return $ this ;
114
+ }
115
+
116
+
98
117
/**
99
118
* @param bool $bool
100
119
*
@@ -180,6 +199,18 @@ public function FieldHolder($properties = array())
180
199
}
181
200
}
182
201
202
+ $ fields = $ this ->getManualFields ();
203
+
204
+ if ($ this ->showLatLngManual ) {
205
+ $ name = $ this ->getName ();
206
+
207
+ $ fields ->removeByName ("{$ name }[Longitude] " );
208
+ $ fields ->removeByName ("{$ name }[Latitude] " );
209
+
210
+ $ fields ->push (new TextField ("{$ name }[Longitude] " , 'Longitude ' ));
211
+ $ fields ->push (new TextField ("{$ name }[Latitude] " , 'Latitude ' ));
212
+ }
213
+
183
214
$ properties = array (
184
215
'ManualAddressFields ' => $ this ->getManualFields (),
185
216
'AddressField ' => $ this ->addressField ->Field (),
@@ -347,6 +378,34 @@ public function validate($validator)
347
378
348
379
return false ;
349
380
}
381
+
382
+ if ($ this ->requireLatLngManual ) {
383
+ $ lat = $ fields ->dataFieldByName ("{$ name }[Latitude] " );
384
+
385
+ if (!$ lat ->Value ()) {
386
+ $ lat ->validationError (
387
+ $ name ,
388
+ _t ("AddressFinderField.LATITUDEMISSING " , "Please enter a valid Latitude. " ),
389
+ "Latitude " ,
390
+ false
391
+ );
392
+
393
+ return false ;
394
+ }
395
+
396
+ $ lng = $ fields ->dataFieldByName ("{$ name }[Longitude] " );
397
+
398
+ if (!$ lng ->Value ()) {
399
+ $ lng ->validationError (
400
+ $ name ,
401
+ _t ("AddressFinderField.LONGTITUDEMISSING " , "Please enter a valid Longitude. " ),
402
+ "Longitude " ,
403
+ false
404
+ );
405
+
406
+ return false ;
407
+ }
408
+ }
350
409
}
351
410
352
411
return true ;
0 commit comments