Hi all:
Not sure if it is because of the way I use the FormSelect view helper
or if I am missing!?

Tried the following code:

$this->_view->formSelect($name, $value,
(is_array($fieldValue['attributes'])?$fieldValue['attributes']:array()),
array('1' => 'Yes', '0' => 'No'))

$value is a tinyint (MySQL). This code checked all drop downs with yes
even if $value was 0.

Changing the code to

$this->_view->formSelect($name, intval( $value ),
(is_array($fieldValue['attributes'])?$fieldValue['attributes']:array()),
array(1 => 'Yes', 0 => 'No'))

works.

According to the view helper source:

        // selected?
        if (in_array($value, $selected, 0 === $value)) { //this is the
options value, not the field value. So it's the key of the array!!!
            $opt .= ' selected="selected"';
        }

if the options value === int 0, in array checks the datatype. In my
initial code it should be string 0 ('0' => 'No'), so it shouldn't
check the datatype. However, the code for some reason didn't work. If
I use int 0 and convert the field value to int 0 with intval, it
works.

Anybody out there that has an idea why this is the case? For now the
second solution works for me, so most likely won't dig any deeper.

TIA

Gunter

Reply via email to