Skip to content

Commit

Permalink
Merge pull request #310 from silverstripeltd/bugfix/read-only-mode-fix
Browse files Browse the repository at this point in the history
ENH Refactor the way selected options are returned for read only tag fields
  • Loading branch information
GuySartorelli authored Oct 7, 2024
2 parents 845794f + efc9f45 commit 63cfb0d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/ReadonlyTagField.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ public function Field($properties = array())
{
$options = array();

foreach ($this->getOptions()->filter('Selected', true) as $option) {
// only get the selected options
foreach ($this->getOptions(true) as $option) {
$options[] = $option->Title;
}

Expand Down
16 changes: 16 additions & 0 deletions tests/TagFieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,22 @@ public function testReadonlyTransformation()
$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()
Expand Down

0 comments on commit 63cfb0d

Please sign in to comment.