#102303Empty radio elements are saved as "on"
Description
When the radio (or select) entry contains an empty value, this value will be saved as “on” in TYPO3 v11. In TYPO3 v10 it was the empty string.
Example Flexform-Configuration:
<settings.size>
<TCEforms>
<label>Größe</label>
<config>
<type>radio</type>
<items>
<numIndex index="0">
<numIndex index="0">Groß</numIndex>
<numIndex index="1"></numIndex>
</numIndex>
<numIndex index="1">
<numIndex index="0">Mittel</numIndex>
<numIndex index="1">medium</numIndex>
</numIndex>
<numIndex index="2">
<numIndex index="0">Klein</numIndex>
<numIndex index="1">small</numIndex>
</numIndex>
</items>
</config>
</TCEforms>
</settings.size>
If the user chooses the first option (Groß), then “on” is saved and when the form is presented again, no option is selected.
When a class or template checks, if settings.size is empty, it would return true in TYPO3 v10 and returns false in TYPO3 v11, because “on” is saved.
The error was introduced in #91787
https://github.com/TYPO3/typo3/commit/757f82d1240497500165435c1db7bdf9e15a48a7#diff-d0d979ea8e3e22f10cbeb8385f2c3812d775ca558f4de30a4b22bf6ce7e0e017
Instead of building the attributes itself, the method now uses GeneralUtility::implodeAttributes, but without the keepBlankAttributes=true parameter. This leads to empty value-attributes being dropped and the browser saves radio-buttons without a value attribute as “on”.
The fix would be easy: Add the keepBlankAttributes=true parameter.
Reviews 2
History 924
-
Garvin Hicking commented 11/02/23, 11:15
-
Gerrit Code Review pushed patch set 1 for main to change 81645 status
NewUnder Review 11/02/23, 12:26 -
Gerrit Code Review pushed patch set 2 for main to change 81645 11/02/23, 12:30
-
Garvin Hicking commented 11/02/23, 19:06
The patch in https://review.typo3.org/c/Packages/TYPO3.CMS/+/81645 contains tests based on the
styleguidebasic TCA elemements.- Create an element of that type (“Form engine elements – input, text, checkbox, radio, none, passthrough, user”)
- Go to tab “in flex” then “radio” and try to set the empty value for “radio (empty)”
- Go to tab “radio” and for radio_4 try to set the element with empty value.
- Setting radio_4 to “nofoo” is not saved. Remains on previous value.
- Setting flex_1.radio_2 is not saved. No radio buttons remain checked.
- Both “empty” values get properly saved.
-
Gerrit Code Review pushed patch set 3 for main to change 81645 11/02/23, 19:07
-
Gerrit Code Review pushed patch set 4 for main to change 81645 11/03/23, 09:57
-
Gerrit Code Review pushed patch set 5 for main to change 81645 11/08/23, 18:58
-
Gerrit Code Review pushed patch set 6 for main to change 81645 11/08/23, 19:19
-
Gerrit Code Review pushed patch set 7 for main to change 81645 11/09/23, 18:10
-
Gerrit Code Review pushed patch set 8 for main to change 81645 11/10/23, 10:49
-
Christian Kuhn commented 11/19/23, 11:11
Did this really work in v10? If so, which patch broke it?
-
Robert Vock commented 11/20/23, 07:18
@lolli This patch broke it:
https://forge.typo3.org/issues/91787This is the diff for the radio-button:
https://github.com/TYPO3/typo3/commit/757f82d1240497500165435c1db7bdf9e15a48a7#diff-d0d979ea8e3e22f10cbeb8385f2c3812d775ca558f4de30a4b22bf6ce7e0e017 -
Garvin Hicking commented 11/20/23, 07:30
Thanks Robert for checking this out, one item less on my agenda for today 🥳
Did you by chance try out the patch and does it work for you properly? -
Robert Vock commented 11/20/23, 07:45
@ghi The patch is working. (I only tested Checkboxes and Radios)
We applied a similar patch using Composer-Patches, which just sets the third argument to
implodeAttributesto true for Checkboxes and Radios and are using it in production.It’s only required for Checkboxes and Radio-Buttons, because those form elements save empty values as “on”. But it does not hurt for other form elements and is more consistent, if applied everywhere.
-
Gerrit Code Review pushed patch set 9 for main to change 81645 11/21/23, 11:41
-
Gerrit Code Review pushed patch set 10 for main to change 81645 11/21/23, 11:43
-
Gerrit Code Review pushed patch set 11 for main to change 81645 11/21/23, 15:19
-
Gerrit Code Review pushed patch set 1 for 12.4 to change 81823 11/21/23, 15:28
-
Gerrit Code Review pushed patch set 12 for main to change 81645 11/21/23, 18:23
-
Garvin Hicking commented and changed status
Under ReviewResolved done0 %100 % 11/21/23, 18:45Applied in changeset commit:accf5dd973d61e9e89ede10279ef6d79f89fb1ef.
-
Gerrit Code Review pushed patch set 2 for 12.4 to change 81823 status
ResolvedUnder Review 11/21/23, 18:53 -
Gerrit Code Review pushed patch set 3 for 12.4 to change 81823 11/21/23, 19:31
-
Garvin Hicking commented and changed status
Under ReviewResolved 11/21/23, 20:30Applied in changeset commit:f56e0354b8bb32cffdd15bb1e8334577e43c46a8.
-
Benni Mack changed status
ResolvedClosed 07/09/24, 15:19
Good catch. It actually seems to occur in other formEngine fields too. I’m on it preparing a patch.