Suggestion #6301

form.select: Possibility to add an emptyOption

Added by Susanne Moog over 12 years ago. Updated over 8 years ago.

Status:
Closed
Priority:
Could have
Assignee:
-
Start date:
2010-02-01
Due date:
% Done:

0%

Estimated time:
Has patch:
No
Tags:

Description

It would be nice to have an emptyOption as attribute for the f:form.select view helper.

So you could write

<f:form.select property="category" options="{categories}"
optionLabelField="name" size="1" id="category" emptyOption="- none -" />

and generate:
<select name="category" size="1" id="category">
<option value="">- none -</option>
<option value="cat1">cat1</option>
<option value="cat2">cat2</option>
<option value="cat3">cat3</option>
</select>

I implemented it with adding in selectViewHelper lines 210 ff (FLOW3 a7 version) these lines:
if ($this->arguments->hasArgument('emptyOption')) {
$options = array('' => $this->arguments['emptyOption']) + $options;
}

and registering it in the initializeArguments method:
$this->registerArgument('emptyOption', 'string', 'If specified, an empty option will be added with the given string as label.');

I can't currently provide a real patch, as I have no svn version here, sorry :(


Files

emptyOption.diff (1.62 KB) emptyOption.diff Henjo Hoeksma, 2010-10-26 11:49
issue_6301.diff (2.07 KB) issue_6301.diff Pascal Dürsteler, 2012-10-09 09:55
#1

Updated by Susanne Moog over 12 years ago

I should have additionally mentioned that the code above just gives the possibility to add the empty option. You will most likely get an error if you try to save it, so the saving part is still missing.

#2

Updated by Peter Niederlag about 12 years ago

adding an Idea from Jochen:

strip "semantics" off the argument. Two options "appendOption" and "prependOption" seems to be cleaner.

This feature is quite often needed in reallife IMO.

#3

Updated by Bastian Waidelich almost 12 years ago

  • Project changed from TYPO3.Fluid to Fluid - ViewHelper - Incubator
  • Category deleted (ViewHelpers)
#4

Updated by Bastian Waidelich almost 12 years ago

  • Subject changed from Possibility to add an emptyOption to the f:form.select view helper to form.select: Possibility to add an emptyOption
#5

Updated by Henjo Hoeksma over 11 years ago

attached a patch that provides a solution Susanne considered. It provides an argument 'prependOption'. The value of the argument is the label of the valueless option tag.

#6

Updated by Alex Kellner about 11 years ago

+1

Thx, sounds like a nice hack, but only a hack at the moment :(

#7

Updated by Bastian Waidelich almost 11 years ago

  • Tracker changed from Feature to Suggestion
#8

Updated by Thomas Löffler over 10 years ago

+1!

What's the status of this issue? Any problems? Or any dissonances?

#9

Updated by Grummfy over 10 years ago

on typo3 4.5.4, to save it correctly I need to replace
$options = array('' => $this->arguments['emptyOption']) + $options;
by this
$options = array('-1' => $this->arguments['emptyOption']) + $options;

And it works

#10

Updated by Dominic Garms about 10 years ago

Hello,

I would love to see this feature merged into fluid, because this is very often required in search form fields. +1

#11

Updated by Pascal Dürsteler over 9 years ago

+1, I count this as a basic requirement.

Personally, I'd do it like this:

includeBlank="--- Choose ---"

which gives you the possibility to either include a blank one with no text or a defined text/translation.

Jochen's idea posted by Peter Niederlag seems nice, however I don't see the benefit of adding something at the end of a select. If you have to add something, that would be at the top.

#12

Updated by Pascal Dürsteler over 9 years ago

Adding diff which introduces

includeBlank="<label>"

to the select view helper. Also introduces a little change to the extbase mapper to treat '' values as NULL values which already is in the code, but not for numeric/arrays, which is required here. This also prevents the discussed error above.

#13

Updated by Pascal Dürsteler about 9 years ago

Looks like this can be closed because of http://forge.typo3.org/issues/26595

#14

Updated by Bastian Waidelich about 9 years ago

  • Status changed from New to Closed
  • Has patch set to No

Pascal Dürsteler wrote:

Looks like this can be closed because of http://forge.typo3.org/issues/26595

Right. Although this still needs to be "forward ported" to Flow

Also available in: Atom PDF