Skip to content
This repository
Browse code

Query param searches for GridFieldAddExistingAutocompleter

Fixes issues with query construction in JS when the search URL
already contains GET paramters (e.g. when using the 'translatable'
module).
  • Loading branch information...
commit 1a91431d39dce6eaa2dd60fa17977693a30fec8f 1 parent 8d38551
Ingo Schommer authored July 17, 2012
4  forms/gridfield/GridFieldAddExistingAutocompleter.php
@@ -156,7 +156,7 @@ public function getManipulatedData(GridField $gridField, SS_List $dataList) {
156 156
 	 */
157 157
 	public function getURLHandlers($gridField) {
158 158
 		return array(
159  
-			'search/$ID' => 'doSearch',
  159
+			'search' => 'doSearch',
160 160
 		);
161 161
 	}
162 162
 	
@@ -181,7 +181,7 @@ public function doSearch($gridField, $request) {
181 181
 
182 182
 		// TODO Replace with DataList->filterAny() once it correctly supports OR connectives
183 183
 		foreach($searchFields as $searchField) {
184  
-			$stmts[] .= sprintf('"%s" LIKE \'%s%%\'', $searchField, $request->param('ID'));
  184
+			$stmts[] .= sprintf('"%s" LIKE \'%s%%\'', $searchField, Convert::raw2sql($request->getVar('gridfield_relationsearch')));
185 185
 		}
186 186
 		$results = $allList->where(implode(' OR ', $stmts))->subtract($gridField->getList());
187 187
 		$results = $results->sort($searchFields[0], 'ASC');
2  javascript/GridField.js
@@ -301,7 +301,7 @@
301 301
 								"X-Pjax" : 'Partial'
302 302
 							},
303 303
 							type: "GET",
304  
-							url: suggestionUrl+'/'+request.term,
  304
+							url: suggestionUrl,
305 305
 							data: form.serialize()+'&'+escape(searchField.attr('name'))+'='+escape(searchField.val()), 
306 306
 							success: function(data) {
307 307
 								response( $.map(JSON.parse(data), function( name, id ) {
4  tests/forms/gridfield/GridFieldAddExistingAutocompleterTest.php
@@ -15,7 +15,7 @@ function testSearch() {
15 15
 		$btns = $parser->getBySelector('.ss-gridfield #action_gridfield_relationfind');
16 16
 
17 17
 		$response = $this->post(
18  
-			'GridFieldAddExistingAutocompleterTest_Controller/Form/field/testfield/search/Team 2',
  18
+			'GridFieldAddExistingAutocompleterTest_Controller/Form/field/testfield/search/?gridfield_relationsearch=Team 2',
19 19
 			array(
20 20
 				(string)$btns[0]['name'] => 1
21 21
 			)
@@ -26,7 +26,7 @@ function testSearch() {
26 26
 		$this->assertEquals(array($team2->ID => 'Team 2'), $result);
27 27
 
28 28
 		$response = $this->post(
29  
-			'GridFieldAddExistingAutocompleterTest_Controller/Form/field/testfield/search/Unknown',
  29
+			'GridFieldAddExistingAutocompleterTest_Controller/Form/field/testfield/search/?gridfield_relationsearch=Unknown',
30 30
 			array(
31 31
 				(string)$btns[0]['name'] => 1
32 32
 			)

0 notes on commit 1a91431

Please sign in to comment.
Something went wrong with that request. Please try again.