mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
BUG Readonly version of GroupedDropdownField
GroupedDropdownField was showing empty values in Readonly mode due to not correctly handling the hierarchical source array. Uses flattened source now in GroupedDropdownField->performReadonlyTransformation()
This commit is contained in:
parent
e341e0aee7
commit
404f450ac3
@ -2,6 +2,7 @@
|
||||
|
||||
namespace SilverStripe\Forms;
|
||||
|
||||
use SilverStripe\ORM\ArrayLib;
|
||||
use SilverStripe\ORM\ArrayList;
|
||||
use SilverStripe\View\ArrayData;
|
||||
|
||||
@ -104,4 +105,14 @@ class GroupedDropdownField extends DropdownField
|
||||
);
|
||||
return $values;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return SingleLookupField
|
||||
*/
|
||||
public function performReadonlyTransformation()
|
||||
{
|
||||
$field = parent::performReadonlyTransformation();
|
||||
$field->setSource(ArrayLib::flatten($this->getSource()));
|
||||
return $field;
|
||||
}
|
||||
}
|
||||
|
@ -129,4 +129,39 @@ class GroupedDropdownFieldTest extends SapphireTest
|
||||
preg_replace('/\s+/', ' ', (string)$field->Field())
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that readonly version of GroupedDropdownField displays all values
|
||||
*/
|
||||
public function testReadonlyValue()
|
||||
{
|
||||
$field = GroupedDropdownField::create(
|
||||
'Test',
|
||||
'Testing',
|
||||
[
|
||||
"1" => "One",
|
||||
"Group One" => [
|
||||
"2" => "Two",
|
||||
"3" => "Three"
|
||||
],
|
||||
"Group Two" => [
|
||||
"4" => "Four"
|
||||
],
|
||||
]
|
||||
);
|
||||
|
||||
// value on first level
|
||||
$field->setValue("1");
|
||||
$this->assertRegExp(
|
||||
'/<span class="readonly" id="Test">One<\/span><input type="hidden" name="Test" value="1" \/>/',
|
||||
(string)$field->performReadonlyTransformation()->Field()
|
||||
);
|
||||
|
||||
// value on first level
|
||||
$field->setValue("2");
|
||||
$this->assertRegExp(
|
||||
'/<span class="readonly" id="Test">Two<\/span><input type="hidden" name="Test" value="2" \/>/',
|
||||
(string)$field->performReadonlyTransformation()->Field()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user