Skip to content

Commit

Permalink
ENH Refactor the way selected options are returned for read only tag …
Browse files Browse the repository at this point in the history
…fields.
  • Loading branch information
adunn49 committed Oct 1, 2024
1 parent 845794f commit efc9f45
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 efc9f45

Please sign in to comment.