From cbf8050f2a533819c49fd0fc213e9416072c9100 Mon Sep 17 00:00:00 2001 From: Loz Calver Date: Mon, 27 Mar 2017 14:33:37 +0100 Subject: [PATCH] Allow use of setHasEmptyDefault() in StringTagField --- code/StringTagField.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/code/StringTagField.php b/code/StringTagField.php index 83a0292..159f268 100644 --- a/code/StringTagField.php +++ b/code/StringTagField.php @@ -161,6 +161,11 @@ class StringTagField extends DropdownField $this->setAttribute('multiple', 'multiple'); } + if ($this->getHasEmptyDefault()) { + $this->setAttribute('data-allow-clear', true); + $this->setAttribute('data-placeholder', $this->getEmptyString() ?: ' '); + } + if ($this->getShouldLazyLoad()) { $this->setAttribute('data-ss-tag-field-suggest-url', $this->getSuggestURL()); } else { @@ -199,6 +204,14 @@ class StringTagField extends DropdownField $values = $this->Value(); + if ($this->getHasEmptyDefault()) { + $options->push(ArrayData::create(array( + 'Value' => '', + 'Title' => '', + 'Selected' => empty($values) + ))); + } + foreach ($source as $value) { $options->push( ArrayData::create(array(