diff --git a/src/TagField.php b/src/TagField.php index 96be219..45cf81e 100644 --- a/src/TagField.php +++ b/src/TagField.php @@ -66,9 +66,10 @@ class TagField extends DropdownField * @param null|DataList $source * @param null|DataList $value */ - public function __construct($name, $title = '', $source = [], $value = null) + public function __construct($name, $title = '', $source = [], $value = null, $titleField = 'Title') { $this->setSourceList($source); + $this->setTitleField($titleField); parent::__construct($name, $title, $source, $value); } @@ -254,10 +255,10 @@ protected function getOptions() } if (is_array($values)) { - $values = DataList::create($dataClass)->filter('Title', $values); + $values = DataList::create($dataClass)->filter($this->titleField, $values); } - $ids = $values->column('Title'); + $ids = $values->column($this->titleField); $titleField = $this->getTitleField(); @@ -283,10 +284,10 @@ public function setValue($value, $source = null) $name = $this->getName(); if ($source->hasMethod($name)) { - $value = $source->$name()->column('Title'); + $value = $source->$name()->column($this->titleField); } } elseif ($value instanceof SS_List) { - $value = $value->column('Title'); + $value = $value->column($this->titleField); } if (!is_array($value)) {