diff --git a/src/TagField.php b/src/TagField.php index 34a5113..8235961 100644 --- a/src/TagField.php +++ b/src/TagField.php @@ -525,6 +525,8 @@ class TagField extends MultiSelectField /** @var ReadonlyTagField $copy */ $copy = $this->castedCopy(ReadonlyTagField::class); $copy->setSourceList($this->getSourceList()); + $copy->setTitleField($this->getTitleField()); + return $copy; } diff --git a/tests/TagFieldTest.php b/tests/TagFieldTest.php index 8429e4a..29e7441 100755 --- a/tests/TagFieldTest.php +++ b/tests/TagFieldTest.php @@ -352,6 +352,12 @@ class TagFieldTest extends SapphireTest $field = new TagField('Tags', '', TagFieldTestBlogTag::get()); $readOnlyField = $field->performReadonlyTransformation(); $this->assertInstanceOf(ReadonlyTagField::class, $readOnlyField); + + // Custom title field + $field = new TagField('Tags', '', TagFieldTestBlogTag::get()); + $field->setTitleField('Name'); + $readOnlyField = $field->performReadonlyTransformation(); + $this->assertEquals('Name', $readOnlyField->getTitleField()); } public function testGetSchemaDataDefaults()