Skip to content

Commit 854fae3

Browse files
committed
Update LiveDropdownField.php
it will show (ex.) result "FC Gradina" no mather if you write "Gradina FC" or "FC Gradina". I think this is better when you trying to find "multi word title"
1 parent 541fba6 commit 854fae3

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

code/dropdown_fields/LiveDropdownField.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,16 @@ public function __construct($name, $title, $className = "SiteTree", $label = "Ti
1616
public function getresults(SS_HTTPRequest $r) {
1717

1818
$q = Convert::raw2sql($r->requestVar('q'));
19-
$results = DataObject::get($this->sourceClass,$this->labelField . " LIKE '%{$q}%'");
19+
$qArray = explode(" ", $q);
20+
if (is_array($qArray) && count($qArray) > 1) {
21+
$where = $this->labelField . "!='' ";
22+
foreach ($qArray as $value) {
23+
$where .= "AND ". $this->labelField . " LIKE '%{$value}%' ";
24+
}
25+
} else {
26+
$where = $this->labelField . " LIKE '%{$q}%'";
27+
}
28+
$results = DataObject::get($this->sourceClass, $where);
2029
if($results) {
2130
$set = new DataObjectSet();
2231
foreach($results->toDropdownMap('ID', $this->labelField) as $key => $val) {
@@ -59,4 +68,4 @@ public function Field() {
5968
}
6069

6170

62-
}
71+
}

0 commit comments

Comments
 (0)