Matthew Weier O'Phinney-3 wrote:
> 
> -- Themselves <[EMAIL PROTECTED]> wrote
> (on Sunday, 21 September 2008, 10:17 PM -0700):
>> Hi guys, I'm just playing with the new Dojo forms in 1.6, and so far
>> they're
>> great, I'm just trying to wrap my head around some of the combobox
>> functionality... 
>> 
>> One of the features of comboboxes is that you can provide a drop down
>> list
>> of options in addition to permitting the user to enter text directly in
>> to
>> the input. This is working fine for me, except for when I try to populate
>> the form for editing a record. 
>> 
>> Unless the value of the field is one of the options in the list, it seems
>> you can't set populate a combobox. I've even tried
>> $form->getElement('field')->setValue($array['key']); in the controller
>> after
>> calling the populate method, and still nothing. 
>> 
>> Is this expected behaviour? I was under the impression that a combobox
>> should cleanly handle values that aren't in the options list, which is
>> kind
>> of the point of them I thought. Or am I missing something here? 
> 
> A few things to understand about ComboBox:
> 
>  * The label displayed is also the value submitted. Don't quite
>    understand why this is the case, but it is.
> 
>  * You can type in a value NOT in the list of values in the ComboBox,
>    and it will submit that value
> 
>  * On the server side, when creating the ComboBox, setting the value to
>    a value not in the list simply will not work; it operates as if it
>    were a multi-select list. This is partly due to limitations of the
>    Zend_Form implementation, and partly due to limitations of how to
>    present that information via markup to Dojo.
> 
> -- 
> Matthew Weier O'Phinney
> Software Architect       | [EMAIL PROTECTED]
> Zend Framework           | http://framework.zend.com/
> 
> 

Thanks for that, Matthew. 

And for the sake of anyone else Googling their way through to this, the
solution is pretty simple. If you're in a situation like mine where you
mostly want users to use data in the dropdown options, but you want it to
support them typing in whatever they want, then in order to get around the
problem of values not populating as you would expect, you can simply go like
this:  


$form->getElement('element')->addMultiOption($option, $value);
$form->populate;


in your controller or wherever you're populating the form, and it'll add the
value to the option list, so the populate will work as expected. 
-- 
View this message in context: 
http://www.nabble.com/Zend-%2B-Dojo-Comboboxes-and-%24form-%3Epopulate-tp19602022p19622355.html
Sent from the Zend Framework mailing list archive at Nabble.com.

Reply via email to