Issue Bug Closed

#107200countrySelect viewhelper doesn't pre-select the current value

Jigal van Hemert 08/04/25, 07:51 updated 12/02/25, 13:58

Description

<f:form.countrySelect property="country" />

Doesn’t select the country that is stored in the country property (Domain model with Country class property)

In the viewhelper the code

$options = $this->createOptions($validCountries);
$selectedValue = $this->getValueAttribute();
$tagContent = $this->renderPrependOptionTag();
foreach ($options as $value => $label) {
    $tagContent .= $this->renderOptionTag($value, $label, $value === $selectedValue);
}

produces an array with options where the key is the two-letter ISO code.
The selectedValue however is a Country object and the method getValueAttribute() tries to get an identifier by calling convertToPlainValue(). Unfortunately that method isn’t aware of Country objects yet and simply returns the entire object instead of the alpha2 property.

Reviews 1