2008年11月25日星期二

Re: [fw-mvc] allow duplicate options in Zend_Form_Select

Hi,

I encountered the same issue, and have been using a custom view helper, but nonetheless I submitted a related issue a while ago regarding same value in multiselects along with a suggestion on how to resolve it:

http://framework.zend.com/issues/browse/ZF-4879

Matthew, from this thread and my personal experience I would gather this NOT being an edge case. I can see many cases in which the select values are the same while the select labels differ, for instance providing end users with options they THINK are different, but behind the scenes, they're not. It's important to not think in terms of key/value here where no two identical keys can exist. It would make for a great enhancement. Please consider.

Bernd

2008/11/25 Matthew Weier O'Phinney <matthew@zend.com>
-- Yi Tang <ytang@mbira.com> wrote
(on Tuesday, 25 November 2008, 10:50 AM -0600):
> exactly.. That would make things so much more flexible to use.

However, it makes two other things more difficult:

 * Default use case of key/value pairs
 * Nested optgroups

The flexibility you want is considered an edge case. Create your own
view helpers and elements that accomodate the use case.


> Hector Virgen wrote:
>
>     It would be nice if the view helper stored the selects value/label pairs as
>     a nested array:
>
>     $this->_options = array(
>         array(
>             'value' => 'foo',
>             'label' => 'Foo 1'
>         ),
>         array(
>             'value' => 'foo',
>             'label' => 'Foo 2'
>         ),
>         / etc. /
>     );
>
>     That would allow for what Yi Tang needs, and also allow for options with no
>     value attribute by specifying null as the value. Of course any getters/
>     setters would have to be modified to prevent breaking BC.
>
>     -Hector
>
>
>     On Mon, Nov 24, 2008 at 4:01 PM, Matthew Weier O'Phinney <matthew@zend.com>
>     wrote:
>
>         -- Yi Tang <ytang@mbira.com> wrote
>         (on Monday, 24 November 2008, 04:24 PM -0600):
>         > I'm trying to add some options with the same value but different
>         texts
>         > to a Zend_Form_Select element, looks like Zend_Form_Select by default
>         > removes all duplicate options.  Is there anyway to get around this?
>
>         Not really. Both the view helper as well as the form element require
>         you
>         to pass an associative array of key/value pairs to create the options
>         --
>         and PHP's associative arrays require unique keys. The only way to get
>         around it would be to create a custom view helper or decorator that
>         generates the markup.
>
>         --
>         Matthew Weier O'Phinney
>         Software Architect       | matthew@zend.com
>         Zend Framework           | http://framework.zend.com/
>
>
>
>

--
Matthew Weier O'Phinney
Software Architect       | matthew@zend.com
Zend Framework           | http://framework.zend.com/



--
___________________________________

Bernd Matzner

Christburger Str. 3
D-10405 Berlin
Telefon: +49 (30) 41715994
Telefax: +49 (30) 41715984
Mobil:   +49 (163) 6289637
Skype:  berndmatzner
E-Mail:  mail@berndmatzner.de
___________________________________

Beruflich:
Informationsarchitekt

Telefon: +49 (30) 80962534
Telefax: +49 (30) 80962536
bernd@matznermatzner.de

MatznerMatzner
http://matznermatzner.de
___________________________________

没有评论: