Bug #49038

form.select does not select the first item if prependOptionValue is used

Added by Axel Brand about 8 years ago.

Status:
New
Priority:
Must have
Assignee:
-
Category:
-
Target version:
-
Start date:
2013-06-11
Due date:
% Done:

0%

Estimated time:
Has patch:
No

Description

I habe a strange behaviour.

I use the f:form.select viewhelper like this:

<f:form.select property="myadata" options="{mydatas}" optionLabelField="name" optionValueField="uid" sortByOptionLabel="TRUE" prependOptionLabel="" />

Here the action:

  1. select first item
  2. save object => everything is fine
  3. edit object
  4. first item is NOT selected

If i try this with the second one or if i delete the prependOptionLabel attribute, everything is running fine.

I hacked the view-helper-class SelectViewHelper.php like this:

protected function isSelected($value) {
         $this->getSelectedValue();
        $selectedValue = $this->getSelectedValue();
        if ($value === $selectedValue || (string) $value === $selectedValue) {
            return TRUE;
        }
        if ($this->hasArgument('multiple')) {
            if (is_null($selectedValue) && $this->arguments['selectAllByDefault'] === TRUE) {
                return TRUE;
            } elseif (is_array($selectedValue) && in_array($value, $selectedValue)) {
                return TRUE;
            }
        }
        return FALSE;
    }

The line

$this->getSelectedValue();

is the trick.

No data to display

Also available in: Atom PDF