Skip to content

Commit fd07eb5

Browse files
committed
Add ability to set whether to allow lat lng entry on manual
1 parent 036acaa commit fd07eb5

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

javascript/addressfinder.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
manual.hide()
2121
}
2222

23+
if (!$(elem).find('.addressfinder__holder input').length) {
24+
return;
25+
}
2326
/* create widget */
2427
widget = new AddressFinder.Widget(field, key, "NZ", {
2528
container: $(elem).find('.addressfinder__holder').get(0)
@@ -53,6 +56,8 @@
5356
} else {
5457
useManual.val('0')
5558
}
59+
60+
return false;
5661
})
5762

5863
/* on manually changing of the fields then we have to clear x/y */

src/AddressFinderField.php

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ class AddressFinderField extends TextField
4444

4545
private static $include_address_finder_js = true;
4646

47+
private $showLatLngManual = false;
48+
49+
private $requireLatLngManual = false;
50+
4751
/**
4852
* @param string $name
4953
* @param string $title
@@ -95,6 +99,21 @@ public function __construct($name, $title = null, $value = null)
9599
parent::__construct($name, $title, $value);
96100
}
97101

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+
98117
/**
99118
* @param bool $bool
100119
*
@@ -180,6 +199,18 @@ public function FieldHolder($properties = array())
180199
}
181200
}
182201

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+
183214
$properties = array(
184215
'ManualAddressFields' => $this->getManualFields(),
185216
'AddressField' => $this->addressField->Field(),
@@ -347,6 +378,34 @@ public function validate($validator)
347378

348379
return false;
349380
}
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+
}
350409
}
351410

352411
return true;

0 commit comments

Comments
 (0)