Project

General

Profile

Actions

Task #82422

closed

Epic #82340: EXT:form - improve documentation

Documentation of "defaultValue"

Added by Forger Service about 7 years ago. Updated about 6 years ago.

Status:
Closed
Priority:
Should have
Assignee:
Category:
Form Framework
Target version:
-
Start date:
2017-09-09
Due date:
% Done:

100%

Estimated time:
TYPO3 Version:
8
PHP Version:
Tags:
Documentation
Complexity:
Sprint Focus:
Remote Sprint

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

form_backend.png (26.2 KB) form_backend.png Ralf Zimmermann, 2017-09-11 13:00
Actions #1

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

Actions #3

Updated by Christian Kuhn about 7 years ago

  • Status changed from Under Review to Rejected
Actions #4

Updated by Clemens Riccabona about 7 years ago

Prepending some option !== preselecting exisiting option by value

just sayin ...

Actions #5

Updated by Clemens Riccabona about 7 years ago

  • Description updated (diff)
Actions #6

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

Actions #7

Updated by Ralf Zimmermann about 7 years ago

  • File deleted (form_backend.png)
Actions #9

Updated by Christian Kuhn about 7 years ago

  • Status changed from Rejected to Under Review

re-opened.

Actions #10

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.

Actions #11

Updated by Ralf Zimmermann over 6 years ago

  • Status changed from Under Review to Accepted
Actions #12

Updated by Ralf Zimmermann over 6 years ago

  • Subject changed from [TASK] Add preselection to SingleSelect to Dokumentation of "defaultValue"
Actions #13

Updated by Ralf Zimmermann over 6 years ago

  • Tags set to Documentation
Actions #14

Updated by Ralf Zimmermann over 6 years ago

  • Parent task set to #82340
Actions #15

Updated by Ralf Zimmermann over 6 years ago

  • Subject changed from Dokumentation of "defaultValue" to Documentation of "defaultValue"
Actions #16

Updated by Björn Jacob over 6 years ago

  • Status changed from Accepted to In Progress
  • Assignee set to Björn Jacob
Actions #17

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

Actions #18

Updated by Björn Jacob over 6 years ago

  • Sprint Focus set to Remote Sprint
Actions #19

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

Actions #20

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

Actions #21

Updated by Björn Jacob over 6 years ago

  • Status changed from Under Review to Resolved
  • % Done changed from 0 to 100
Actions #22

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

Actions #23

Updated by Björn Jacob over 6 years ago

  • Status changed from Under Review to Resolved
Actions #24

Updated by Benni Mack about 6 years ago

  • Status changed from Resolved to Closed
Actions

Also available in: Atom PDF