FIX Use existing source datalist if available before creating a new one (closes #171)

Fix for #171 - Issue when utilizing multiple of same parent class

Co-authored-by: Joe Madden <joe.madden@moosylvania.com>
This commit is contained in:
Joseph Madden 2021-10-14 19:38:53 -05:00 committed by Michal Kleiner
parent 43ccb16def
commit b81546d555

View File

@ -275,8 +275,12 @@ class TagField extends MultiSelectField
// Convert an array of values into a datalist of options
if (!$values instanceof SS_List) {
if (is_array($values) && !empty($values)) {
$values = DataList::create($dataClass)
->filter($this->getTitleField(), $values);
if (is_a($source, DataList::class)) {
$values = $source->filter($this->getTitleField(), $values);
} else {
$values = DataList::create($dataClass)
->filter($this->getTitleField(), $values);
}
} else {
$values = ArrayList::create();
}