Merge pull request #4503 from patricknelson/issue-4502-sort-autocomplete

FIX for #4502 Prevents JSON.parse() from scrambling sorted results from server-side.
This commit is contained in:
Daniel Hensby 2015-08-19 11:43:29 +01:00
commit 0768434997
3 changed files with 12 additions and 5 deletions

View File

@ -218,7 +218,12 @@ class GridFieldAddExistingAutocompleter
$originalSourceFileComments = Config::inst()->get('SSViewer', 'source_file_comments');
Config::inst()->update('SSViewer', 'source_file_comments', false);
foreach($results as $result) {
$json[$result->ID] = html_entity_decode(SSViewer::fromString($this->resultsFormat)->process($result));
$title = html_entity_decode(SSViewer::fromString($this->resultsFormat)->process($result));
$json[] = array(
'label' => $title,
'value' => $title,
'id' => $result->ID,
);
}
Config::inst()->update('SSViewer', 'source_file_comments', $originalSourceFileComments);
return Convert::array2json($json);

View File

@ -371,9 +371,7 @@
url: $(searchField).data('searchUrl'),
data: encodeURIComponent(searchField.attr('name'))+'='+encodeURIComponent(searchField.val()),
success: function(data) {
response( $.map(JSON.parse(data), function( name, id ) {
return { label: name, value: name, id: id };
}));
response(JSON.parse(data));
},
error: function(e) {
alert(ss.i18n._t('GRIDFIELD.ERRORINTRANSACTION', 'An error occured while fetching data from the server\n Please try again later.'));

View File

@ -41,7 +41,11 @@ class GridFieldAddExistingAutocompleterTest extends FunctionalTest {
$this->assertFalse($response->isError());
$result = Convert::json2array($response->getBody());
$this->assertEquals(1, count($result));
$this->assertEquals(array($team2->ID => 'Team 2'), $result);
$this->assertEquals(array(array(
'label' => 'Team 2',
'value' => 'Team 2',
'id' => $team2->ID,
)), $result);
$response = $this->post(
'GridFieldAddExistingAutocompleterTest_Controller/Form/field/testfield/'