Task #82422

Epic #82340: EXT:form - improve documentation

Documentation of "defaultValue"

Added by Forger Service almost 2 years ago. Updated 11 months ago.

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

100%

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' ...

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

Associated revisions

Revision 54c6773a (diff)
Added by Bjoern Jacob over 1 year ago

[TASK] Document 'defaultValue' handling of form

The form framework supports setting a 'defaultValue' for most
of the form elements. This patch adds some information about
this setting and outlines the difference to the 'prependOptionValue'
setting.

Resolves: #82422
Releases: master, 8.7
Change-Id: Ic3bbe76ebe69ac0655e11ba501d62ee19b2d143f
Reviewed-on: https://review.typo3.org/56991
Reviewed-by: Anja Leichsenring <>
Tested-by: Anja Leichsenring <>
Tested-by: TYPO3com <>
Reviewed-by: Ralf Zimmermann <>
Tested-by: Ralf Zimmermann <>
Reviewed-by: Susanne Moog <>
Tested-by: Susanne Moog <>

Revision 88e332a9 (diff)
Added by Bjoern Jacob over 1 year ago

[TASK] Document 'defaultValue' handling of form

The form framework supports setting a 'defaultValue' for most
of the form elements. This patch adds some information about
this setting and outlines the difference to the 'prependOptionValue'
setting.

Resolves: #82422
Releases: master, 8.7
Change-Id: Ic3bbe76ebe69ac0655e11ba501d62ee19b2d143f
Reviewed-on: https://review.typo3.org/56993
Tested-by: TYPO3com <>
Reviewed-by: Ralf Zimmermann <>
Tested-by: Ralf Zimmermann <>

History

#1 Updated by Gerrit Code Review almost 2 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

#3 Updated by Christian Kuhn almost 2 years ago

  • Status changed from Under Review to Rejected

#4 Updated by Clemens Riccabona almost 2 years ago

Prepending some option !== preselecting exisiting option by value

just sayin ...

#5 Updated by Clemens Riccabona almost 2 years ago

  • Description updated (diff)

#6 Updated by Ralf Zimmermann almost 2 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

#7 Updated by Ralf Zimmermann almost 2 years ago

  • File deleted (form_backend.png)

#9 Updated by Christian Kuhn almost 2 years ago

  • Status changed from Rejected to Under Review

re-opened.

#10 Updated by Ralf Zimmermann almost 2 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.

#11 Updated by Ralf Zimmermann over 1 year ago

  • Status changed from Under Review to Accepted

#12 Updated by Ralf Zimmermann over 1 year ago

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

#13 Updated by Ralf Zimmermann over 1 year ago

  • Tags set to Documentation

#14 Updated by Ralf Zimmermann over 1 year ago

  • Parent task set to #82340

#15 Updated by Ralf Zimmermann over 1 year ago

  • Subject changed from Dokumentation of "defaultValue" to Documentation of "defaultValue"

#16 Updated by Bjoern Jacob over 1 year ago

  • Status changed from Accepted to In Progress
  • Assignee set to Bjoern Jacob

#17 Updated by Gerrit Code Review over 1 year 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

#18 Updated by Bjoern Jacob over 1 year ago

  • Sprint Focus set to Remote Sprint

#19 Updated by Gerrit Code Review over 1 year 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

#20 Updated by Gerrit Code Review over 1 year 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

#21 Updated by Bjoern Jacob over 1 year ago

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

#22 Updated by Gerrit Code Review over 1 year 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

#23 Updated by Bjoern Jacob over 1 year ago

  • Status changed from Under Review to Resolved

#24 Updated by Benni Mack 11 months ago

  • Status changed from Resolved to Closed

Also available in: Atom PDF