Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH Refactor the way selected options are returned for read only tag fields #310

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading