This is ONLY a documentation task.
The "defaultValue" fallback is done within:
\TYPO3\CMS\Fluid\ViewHelpers\Form\AbstractFormFieldViewHelper::getPropertyValue()
ObjectAccess::getPropertyPath($formObject, $this->arguments['property']);
$formObject = TYPO3\CMS\Form\Domain\Runtime\FormRuntime which implements \ArrayAccess.
If $formObject[$formElementIdentifier] has no value (and "value" means "submitted data"), then the FormRuntime returns the value from the property "defaultValue".
If you set the viewhelpers "value" property with the elements "defaultValue" property than this value will be selected every time!
Please make a formDefinition and add 2 pages
type: Form
identifier: select-test
label: select-test
prototypeName: standard
renderables:
-
type: Page
identifier: page-1
label: Step
renderables:
-
type: MultiSelect
identifier: multiselect-1
label: 'Multi select'
properties:
options:
foo1: bar1
foo2: bar2
foo3: bar3
type: MultiSelect
identifier: multiselect-1
label: 'Multi select'
defaultValue:
- foo1
- foo3
-
type: SummaryPage
identifier: summarypage-1
label: 'Summary step'
select "bar2" and go to the summary step. Now go back to the first step. As you can see, patchset 1 will select the selection from the "defaultValue" property again.
But without the patchset 1 every is still fine.
Or use it by code (without the patchset 1):
formDefinition:
type: Form
identifier: select-test
label: select-test
prototypeName: standard
renderables:
-
type: Page
identifier: page-1
label: Step
renderables:
-
type: MultiSelect
identifier: multiselect-1
label: 'Multi select'
type: MultiSelect
identifier: multiselect-1
label: 'Multi select'
-
type: SummaryPage
identifier: summarypage-1
label: 'Summary step'
ext_localconf.php
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/form']['initializeFormElement'][1506431770]
= \TRITUM\FormExample\Hooks\SelectHook::class;
Classes/Hooks/SelectHook.php
<?php
namespace TRITUM\FormExample\Hooks;
use TYPO3\CMS\Form\Domain\Model\Renderable\RenderableInterface;
class SelectHook
{
public function initializeFormElement(RenderableInterface $renderable)
{
if ($renderable->getUniqueIdentifier() === 'select-test-1-multiselect-1') {
$renderable->setProperty('options', [
'foo1' => 'bar1',
'foo2' => 'bar2',
'foo3' => 'bar3'
]);
$renderable->setDefaultValue([
'foo1',
'foo3'
]);
}
}
}
Works for me. Since the "defaultValue" property is missing within the docs, this should be covered by this patch, but NOT the template changes.