Merge pull request #93 from kinglozzer/hasemptydefault

Allow use of setHasEmptyDefault() in StringTagField
This commit is contained in:
Daniel Hensby 2017-03-30 17:11:29 +01:00 committed by GitHub
commit b6077221ac
1 changed files with 13 additions and 0 deletions

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(