Task #82422
closedEpic #82340: EXT:form - improve documentation
Documentation of "defaultValue"
100%
Description
Add the defaultValue option, supported by form viewhelper also to SingleSelect of ext:form, so one could define a preselected value of a select-field.
This issue was automatically created from https://github.com/TYPO3/TYPO3.CMS/pull/81
I will give an example here (after being rejected):
you add a select for countries, derived from static_info_tables.
you want e.g. germany or austria preselected in this dropdown.
if you have only the prependOption possibilites, which Ralf Zimmermann labels as 'implemented' you need to grab that values in your array of your field.
you need to remove them from there and add key and value to prependOption key and value.
brutal.
furthermore you will destroy the ordering of the select, suddenly being germany the very first entry of the select. therefore you are breaking the navigation via keyboard through the options of the select, at least for these users, who want to fast-forward to the countries starting with 'G' ...
Files
Updated by Gerrit Code Review about 7 years ago
- Status changed from New to Under Review
Patch set 1 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/54078
Updated by Ralf Zimmermann about 7 years ago
- Category set to Form Framework
This is already implemented:
https://docs.typo3.org/typo3cms/extensions/form/latest/Config/proto/formElements/formElementTypes/SingleSelect.html#properties-prependoptionlabel
https://docs.typo3.org/typo3cms/extensions/form/latest/Config/proto/formElements/formElementTypes/SingleSelect.html#properties-prependoptionvalue
Updated by Christian Kuhn about 7 years ago
- Status changed from Under Review to Rejected
Updated by Clemens Riccabona about 7 years ago
Prepending some option !== preselecting exisiting option by value
just sayin ...
Updated by Ralf Zimmermann about 7 years ago
- File form_backend.png added
The default value is also implemented IMHO.
type: SingleSelect
identifier: singleselect-1
label: 'Single select'
defaultValue: wwwwww
properties:
options:
sdf: sdf
wwwwww: www
Updated by Ralf Zimmermann about 7 years ago
- File form_backend.png form_backend.png added
Updated by Ralf Zimmermann about 7 years ago
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.
Updated by Ralf Zimmermann over 6 years ago
- Status changed from Under Review to Accepted
Updated by Ralf Zimmermann over 6 years ago
- Subject changed from [TASK] Add preselection to SingleSelect to Dokumentation of "defaultValue"
Updated by Ralf Zimmermann over 6 years ago
- Subject changed from Dokumentation of "defaultValue" to Documentation of "defaultValue"
Updated by Björn Jacob over 6 years ago
- Status changed from Accepted to In Progress
- Assignee set to Björn Jacob
Updated by Gerrit Code Review over 6 years ago
- Status changed from In Progress to Under Review
Patch set 1 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/56991
Updated by Gerrit Code Review over 6 years ago
Patch set 2 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/56991
Updated by Gerrit Code Review over 6 years ago
Patch set 3 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/56991
Updated by Björn Jacob over 6 years ago
- Status changed from Under Review to Resolved
- % Done changed from 0 to 100
Applied in changeset 54c6773a85cd152dde1dd8b6c21609a4c68bc35b.
Updated by Gerrit Code Review over 6 years ago
- Status changed from Resolved to Under Review
Patch set 1 for branch TYPO3_8-7 of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/56993
Updated by Björn Jacob over 6 years ago
- Status changed from Under Review to Resolved
Applied in changeset 88e332a9e50610cb935906d97e8c03bf4f234983.