Allow use of setHasEmptyDefault() in StringTagField

This commit is contained in:
Loz Calver 2017-03-27 14:33:37 +01:00
parent e205fb4f6d
commit cbf8050f2a

View File

@ -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(