mirror of
https://github.com/silverstripe/silverstripe-tagfield
synced 2024-10-22 11:05:32 +02:00
Merge pull request #57 from tractorcow/pulls/fix-source
BUG Fix items not included from source appearing in suggestions
This commit is contained in:
commit
641128f2d6
@ -332,13 +332,11 @@ class TagField extends DropdownField {
|
||||
*/
|
||||
$source = $this->getSource();
|
||||
|
||||
$dataClass = $source->dataClass();
|
||||
|
||||
$titleField = $this->getTitleField();
|
||||
|
||||
$term = Convert::raw2sql($term);
|
||||
|
||||
$query = $dataClass::get()
|
||||
$query = $source
|
||||
->filter($titleField . ':PartialMatch:nocase', $term)
|
||||
->sort($titleField)
|
||||
->limit($this->getLazyLoadItemLimit());
|
||||
|
@ -147,6 +147,44 @@ class TagFieldTest extends SapphireTest {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that TagField supports pre-filtered data sources
|
||||
*/
|
||||
public function testRestrictedSuggestions() {
|
||||
$source = TagFieldTestBlogTag::get()->exclude('Title', 'Tag2');
|
||||
$field = new TagField('Tags', '', $source);
|
||||
|
||||
/**
|
||||
* Partial tag title match.
|
||||
*/
|
||||
$request = $this->getNewRequest(array('term' => 'Tag'));
|
||||
|
||||
$this->assertEquals(
|
||||
'{"items":[{"id":1,"text":"Tag1"}]}',
|
||||
$field->suggest($request)->getBody()
|
||||
);
|
||||
|
||||
/**
|
||||
* Exact tag title match.
|
||||
*/
|
||||
$request = $this->getNewRequest(array('term' => 'Tag1'));
|
||||
|
||||
$this->assertEquals(
|
||||
'{"items":[{"id":1,"text":"Tag1"}]}',
|
||||
$field->suggest($request)->getBody()
|
||||
);
|
||||
|
||||
/**
|
||||
* Excluded item doesn't appear in matches
|
||||
*/
|
||||
$request = $this->getNewRequest(array('term' => 'Tag2'));
|
||||
|
||||
$this->assertEquals(
|
||||
'{"items":[]}',
|
||||
$field->suggest($request)->getBody()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $parameters
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user