Multiselect selected values

10 messages Options
Embed this post
Permalink
Joó Ádám

Multiselect selected values

Reply Threaded More More options
Print post
Permalink
Hi,

How can I set the selected values in a multiselect element? I tried to
call setValue() multiple times and also passing an array to it, but
none of them worked.


Thanks,
Ádám
weierophinney

Re: Multiselect selected values

Reply Threaded More More options
Print post
Permalink
-- Joó Ádám <[hidden email]> wrote
(on Friday, 20 February 2009, 07:08 PM +0100):
> How can I set the selected values in a multiselect element? I tried to
> call setValue() multiple times and also passing an array to it, but
> none of them worked.

Passing an array of values to setValue() should work. The values in the
array should correspond to the keys passed when setting the
multiOptions:

    $multi->setMultiOptions(array(
        'foo' => 'Foo',
        'bar' => 'Bar',
        'baz' => 'Baz',
        'bat' => 'Bat',
    ));
    $multi->setValue(array('foo', 'bat'));

--
Matthew Weier O'Phinney
Software Architect       | [hidden email]
Zend Framework           | http://framework.zend.com/
Joó Ádám

Re: Multiselect selected values

Reply Threaded More More options
Print post
Permalink
> Passing an array of values to setValue() should work.

Yeah, and it works just fine, thuogh I wasn't aware of that because I
had to check the HTML source to see it: Firefox for some reason
doesn't display the selection when it is under my .lc (localhost, for
development) TLD…


Thank you,
Ádám
Ajit

Multiselect selected values

Reply Threaded More More options
Print post
Permalink
In reply to this post by weierophinney

Hi

i have a problem in Multiselect selected values. it should select 'My Community for Friends'
this value, but it is not working.

$aGroups = Array ( [3] => My Community for Friends [4] => Electronics )

$sGroup = Array ( [0] => 3 )

$groups = new Zend_Form_Element_Select('group');
           
                        $groups ->setLabel('Groups:')
                                          ->setDecorators($this->elementDecorators)
                                          ->setRegisterInArrayValidator(false)
                                          ->setValue($sGroup)
                                          ->setAttrib('multiple','multiple')  
                                          ->addMultiOptions($aGroups);
           
            $this->addElement($groups);



drm-4

Re: Multiselect selected values

Reply Threaded More More options
Print post
Permalink
ajitk15 wrote:
> $groups = new Zend_Form_Element_Select('group');
>    
> $groups ->setLabel('Groups:')
>  ->setAttrib('multiple','multiple')
>  

Hi, you should use Zend_Form_Element_Multiselect for this.
Ajit

Re: Multiselect selected values

Reply Threaded More More options
Print post
Permalink
even i tried with  Zend_Form_Element_Multiselect also
still the same issue.


drm-4 wrote:
ajitk15 wrote:
> $groups = new Zend_Form_Element_Select('group');
>    
> $groups ->setLabel('Groups:')
>  ->setAttrib('multiple','multiple')
>  

Hi, you should use Zend_Form_Element_Multiselect for this.
Hector Virgen

Re: Multiselect selected values

Reply Threaded More More options
Print post
Permalink
If you're using a regular select, the value you pass to setValue should be a single value (not an array).

If you're using MultiSelect, then you need to pass in an array of values.

--
Hector


On Tue, Oct 27, 2009 at 8:41 AM, ajitk15 <[hidden email]> wrote:

even i tried with  Zend_Form_Element_Multiselect also
still the same issue.



drm-4 wrote:
>
> ajitk15 wrote:
>> $groups = new Zend_Form_Element_Select('group');
>>
>>                      $groups ->setLabel('Groups:')
>>                                        ->setAttrib('multiple','multiple')
>>
>
> Hi, you should use Zend_Form_Element_Multiselect for this.
>
>

--
View this message in context: http://www.nabble.com/Multiselect-selected-values-tp22125736p26079939.html
Sent from the Zend Framework mailing list archive at Nabble.com.


Ajit

Re: Multiselect selected values

Reply Threaded More More options
Print post
Permalink
Hi

this using the Zend_Form_Element_Multiselect still i the same issue
can any one help me out in this asap


 $groups = new Zend_Form_Element_Multiselect('group');

                        $groups ->setLabel('Groups:')
                                          ->setDecorators($this->elementDecorators)
                                          ->setRegisterInArrayValidator(false)
                                           ->setAttrib('multiple','multiple')
                                          ->setValue($sGroup)
                                          ->addMultiOptions($aGroups);
           
            $this->addElement($groups);




Hector Virgen wrote:
If you're using a regular select, the value you pass to setValue should be a
single value (not an array).

If you're using MultiSelect, then you need to pass in an array of values.

--
Hector


On Tue, Oct 27, 2009 at 8:41 AM, ajitk15 <ajit@endofthenight.com> wrote:

>
> even i tried with  Zend_Form_Element_Multiselect also
> still the same issue.
>
>
>
> drm-4 wrote:
> >
> > ajitk15 wrote:
> >> $groups = new Zend_Form_Element_Select('group');
> >>
> >>                      $groups ->setLabel('Groups:')
> >>
>  ->setAttrib('multiple','multiple')
> >>
> >
> > Hi, you should use Zend_Form_Element_Multiselect for this.
> >
> >
>
> --
> View this message in context:
> http://www.nabble.com/Multiselect-selected-values-tp22125736p26079939.html
> Sent from the Zend Framework mailing list archive at Nabble.com.
>
>
A.J. Brown-3

Re: Multiselect selected values

Reply Threaded More More options
Print post
Permalink
Have you tried:

->setDefault( $sGroup )

?

On Fri, Oct 30, 2009 at 7:28 AM, ajitk15 <[hidden email]> wrote:

>
> Hi
>
> this using the Zend_Form_Element_Multiselect still i the same issue
> can any one help me out in this asap
>
>
>  $groups = new Zend_Form_Element_Multiselect('group');
>
>                        $groups ->setLabel('Groups:')
>                                          ->setDecorators($this->elementDecorators)
>                                          ->setRegisterInArrayValidator(false)
>                                           ->setAttrib('multiple','multiple')
>                                          ->setValue($sGroup)
>                                          ->addMultiOptions($aGroups);
>
>                $this->addElement($groups);
>
>
>
>
>
> Hector Virgen wrote:
>>
>> If you're using a regular select, the value you pass to setValue should be
>> a
>> single value (not an array).
>>
>> If you're using MultiSelect, then you need to pass in an array of values.
>>
>> --
>> Hector
>>
>>
>> On Tue, Oct 27, 2009 at 8:41 AM, ajitk15 <[hidden email]> wrote:
>>
>>>
>>> even i tried with  Zend_Form_Element_Multiselect also
>>> still the same issue.
>>>
>>>
>>>
>>> drm-4 wrote:
>>> >
>>> > ajitk15 wrote:
>>> >> $groups = new Zend_Form_Element_Select('group');
>>> >>
>>> >>                      $groups ->setLabel('Groups:')
>>> >>
>>>  ->setAttrib('multiple','multiple')
>>> >>
>>> >
>>> > Hi, you should use Zend_Form_Element_Multiselect for this.
>>> >
>>> >
>>>
>>> --
>>> View this message in context:
>>> http://www.nabble.com/Multiselect-selected-values-tp22125736p26079939.html
>>> Sent from the Zend Framework mailing list archive at Nabble.com.
>>>
>>>
>>
>>
>
> --
> View this message in context: http://old.nabble.com/Multiselect-selected-values-tp22125736p26128468.html
> Sent from the Zend Framework mailing list archive at Nabble.com.
>
>



--
A.J. Brown
web | http://ajbrown.org
phone | (937) 660-3969
Ajit

Re: Multiselect selected values

Reply Threaded More More options
Print post
Permalink
I missed out some code in my controller
Now it is working  with this code


Form

$groups = new Zend_Form_Element_Multiselect('group');

                        $groups ->setLabel('Groups:')
                                          ->setDecorators($this->elementDecorators)
                                          ->setRegisterInArrayValidator(false)
                                          ->setAttrib('multiple','multiple')
                                          ->setMultiOptions($aGroups);
           
            $this->addElement($groups);

Controller

$productForm = $oFrmProduct->getEditProductForm($aGroups, $groupsCnt, $buttonMessage);
$productForm->group->setValue($sGroup);


Thanks for all


A.J. Brown-3 wrote:
Have you tried:

->setDefault( $sGroup )

?

On Fri, Oct 30, 2009 at 7:28 AM, ajitk15 <ajit@endofthenight.com> wrote:
>
> Hi
>
> this using the Zend_Form_Element_Multiselect still i the same issue
> can any one help me out in this asap
>
>
>  $groups = new Zend_Form_Element_Multiselect('group');
>
>                        $groups ->setLabel('Groups:')
>                                          ->setDecorators($this->elementDecorators)
>                                          ->setRegisterInArrayValidator(false)
>                                           ->setAttrib('multiple','multiple')
>                                          ->setValue($sGroup)
>                                          ->addMultiOptions($aGroups);
>
>                $this->addElement($groups);
>
>
>
>
>
> Hector Virgen wrote:
>>
>> If you're using a regular select, the value you pass to setValue should be
>> a
>> single value (not an array).
>>
>> If you're using MultiSelect, then you need to pass in an array of values.
>>
>> --
>> Hector
>>
>>
>> On Tue, Oct 27, 2009 at 8:41 AM, ajitk15 <ajit@endofthenight.com> wrote:
>>
>>>
>>> even i tried with  Zend_Form_Element_Multiselect also
>>> still the same issue.
>>>
>>>
>>>
>>> drm-4 wrote:
>>> >
>>> > ajitk15 wrote:
>>> >> $groups = new Zend_Form_Element_Select('group');
>>> >>
>>> >>                      $groups ->setLabel('Groups:')
>>> >>
>>>  ->setAttrib('multiple','multiple')
>>> >>
>>> >
>>> > Hi, you should use Zend_Form_Element_Multiselect for this.
>>> >
>>> >
>>>
>>> --
>>> View this message in context:
>>> http://www.nabble.com/Multiselect-selected-values-tp22125736p26079939.html
>>> Sent from the Zend Framework mailing list archive at Nabble.com.
>>>
>>>
>>
>>
>
> --
> View this message in context: http://old.nabble.com/Multiselect-selected-values-tp22125736p26128468.html
> Sent from the Zend Framework mailing list archive at Nabble.com.
>
>



--
A.J. Brown
web | http://ajbrown.org
phone | (937) 660-3969