mirror of
https://github.com/silverstripe/silverstripe-tagfield
synced 2024-10-22 11:05:32 +02:00
ENH Refactor the way selected options are returned for read only tag fields.
This commit is contained in:
parent
845794fb99
commit
efc9f45962
@ -27,7 +27,8 @@ class ReadonlyTagField extends TagField
|
||||
{
|
||||
$options = array();
|
||||
|
||||
foreach ($this->getOptions()->filter('Selected', true) as $option) {
|
||||
// only get the selected options
|
||||
foreach ($this->getOptions(true) as $option) {
|
||||
$options[] = $option->Title;
|
||||
}
|
||||
|
||||
|
@ -408,6 +408,22 @@ class TagFieldTest extends SapphireTest
|
||||
$field->setTitleField('Name');
|
||||
$readOnlyField = $field->performReadonlyTransformation();
|
||||
$this->assertEquals('Name', $readOnlyField->getTitleField());
|
||||
|
||||
// Also check Field options
|
||||
$field = new TagField('Tags', '', TagFieldTestBlogTag::get());
|
||||
$field->setTitleField('Title');
|
||||
$field->setValue(['Tag1']);
|
||||
|
||||
// When not read only (and not lazy-loading) all source options are returned
|
||||
$htmlText = $field->Field();
|
||||
$this->assertStringContainsString('Tag1', $htmlText);
|
||||
$this->assertStringContainsString('222', $htmlText);
|
||||
|
||||
// When read only mode, only selected options are returned
|
||||
$readOnlyField = $field->performReadonlyTransformation();
|
||||
$htmlText = $readOnlyField->Field();
|
||||
$this->assertStringContainsString('Tag1', $htmlText);
|
||||
$this->assertStringNotContainsString('222', $htmlText);
|
||||
}
|
||||
|
||||
public function testItDisplaysWithSelectedValuesFromDataList()
|
||||
|
Loading…
Reference in New Issue
Block a user