mirror of
https://github.com/silverstripe/silverstripe-tagfield
synced 2024-10-22 11:05:32 +02:00
Merge pull request #162 from tractorcow/pulls/fix-react
This commit is contained in:
commit
66aa1af72a
@ -6,7 +6,6 @@ use Exception;
|
||||
use SilverStripe\Control\Controller;
|
||||
use SilverStripe\Control\HTTPRequest;
|
||||
use SilverStripe\Control\HTTPResponse;
|
||||
use SilverStripe\Core\Convert;
|
||||
use SilverStripe\Core\Injector\Injector;
|
||||
use SilverStripe\Forms\MultiSelectField;
|
||||
use SilverStripe\Forms\Validator;
|
||||
@ -319,7 +318,15 @@ class TagField extends MultiSelectField
|
||||
return parent::setValue($value);
|
||||
}
|
||||
|
||||
return parent::setValue(array_filter($value));
|
||||
// Safely map php / react-select values to flat list
|
||||
$values = [];
|
||||
foreach ($value as $item) {
|
||||
if ($item) {
|
||||
$values[] = isset($item['Value']) ? $item['Value'] : $item;
|
||||
}
|
||||
}
|
||||
|
||||
return parent::setValue($values);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -131,6 +131,30 @@ class TagFieldTest extends SapphireTest
|
||||
$record
|
||||
);
|
||||
}
|
||||
|
||||
public function testSavesReactTags()
|
||||
{
|
||||
$record = $this->getNewTagFieldTestBlogPost('BlogPost1');
|
||||
$record->write();
|
||||
|
||||
$field = new TagField('Tags', '', new DataList(TagFieldTestBlogTag::class));
|
||||
$field->setValue([
|
||||
[
|
||||
'Title' => 'Tag1',
|
||||
'Value' => 'Tag1',
|
||||
],
|
||||
[
|
||||
'Title' => 'Tag2',
|
||||
'Value' => 'Tag2',
|
||||
],
|
||||
]);
|
||||
$field->saveInto($record);
|
||||
|
||||
$this->compareExpectedAndActualTags(
|
||||
['Tag1', 'Tag2'],
|
||||
$record
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure that {@see TagField::saveInto} respects existing tags
|
||||
|
Loading…
Reference in New Issue
Block a user