From fa754f3fd3cde7129473f380f5f471d97c933a52 Mon Sep 17 00:00:00 2001 From: Simon Gow Date: Fri, 7 Sep 2018 17:28:05 +1200 Subject: [PATCH] TagField lazy load shouldnt render Options TagField should only render options if the lazy load value isn't set. Options from here come from subsequent POSTs, and rendering the options for every request significantly slows down both the form generation and render. --- src/TagField.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/TagField.php b/src/TagField.php index 88b0b16..3968c3f 100644 --- a/src/TagField.php +++ b/src/TagField.php @@ -262,6 +262,20 @@ class TagField extends DropdownField $ids = $values->column($this->getTitleField()); $titleField = $this->getTitleField(); + + if ($this->shouldLazyLoad) { + // only render options that are selected as everything else should be lazy loaded, and or loaded by the form + foreach ($values as $value) { + $options->push( + ArrayData::create(array( + 'Title' => $value->$titleField, + 'Value' => $value->Title, + 'Selected' => true, // only values are iterated. + )) + ); + } + return $options; + } foreach ($source as $object) { $options->push(