here's how one of the select is declared in form
$element = new Zend_Form_Element_Select('patientid');
$element->addMultiOptions($this->patients_array)
->setRequired(true)
->setLabel('label_db_patient_select')
->setAttrib('size', 1)
->setAttrib('maxlength', 1)
->addFilter($filterTags)
->addFilter($filterTrim)
->addValidator($validatorNotEmpty, true)
->addValidator($validatorNum, true)
;
$this->addElement($element);
When I get data from db I just do a populate.
$this->_form->populate($rowset->current()->toArray());
So you can see I never use the setValue.
In your case I think you should try without it and for a new record
after initializing the form
do a
$this->_form->getElement('whatever')->setValue(9);
After I've no idea ...
Chris Tankersley wrote:
> Actually, the setValue in the init is working fine. What I'm having a
> problem with is after I populate the form with data the select isn't
> changing to the populated value.
>
> Chris
>
> On Thu, Sep 11, 2008 at 10:50 AM, Bruno Friedmann <[EMAIL PROTECTED]> wrote:
>> Ok sorry.
>>
>> I'm doing what you want in several forms but index are always called by
>> string.
>> Have you try a setValue('9') if I imagine you have a id='9'
>> value='Something in the list'
>>
>> Hope this help a bit more ...
>>
>>
>> Chris Tankersley wrote:
>>> In my case I want the default to be the last value added instead of
>>> the first which is why I manually do a setValue in the init.
>>>
>>> Chris
>>>
>>>
>>> On Thu, Sep 11, 2008 at 10:19 AM, Bruno Friedmann <[EMAIL PROTECTED]> wrote:
>>>> Chris Tankersley wrote:
>>>>> I have a select element inside of a form object where I call
>>>>> ->setValue() on the form's initialization to select a default value.
>>>>> When I do a $form->populate($data) in my controller the value for this
>>>>> select element is not being set correctly and always defaults to the
>>>>> default value from initialization. My other select elements in the
>>>>> form work fine except for this one.
>>>>>
>>>>> ====FORM====
>>>>> $protClass = new Zend_Form_Element_Select('protClass');
>>>>> $protClass->setLable('Protection Class:')
>>>>> ->setRequired(true)
>>>>> ->setValue(9)
>>>>> ->setMultiOptions($protClassRange);
>>>>>
>>>>> ====CONTROLLER====
>>>>> $form->populate($rate->toArray()); // this has protClass at the correct
>>>>> value
>>>> Dear Chris, in my case there's no need to setValue when populate ..
>>>> it's done auto.
>>>>
>>>>
>>>> --
--
Bruno Friedmann