Re: Extending QF Select
| From: | Justin Patrin | Date: | Wed, 22 Dec 2004 17:54:13 +0000 |
| Subject: | Re: Extending QF Select | ||
| References: | 1 2 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-16419@lists.php.net to get a copy of this message | ||
On Wed, 22 Dec 2004 16:05:17 +0300, Alexey Borzov <borz_off@cs.msu.su> wrote:
> Hi,
>
> Aaron Wormus wrote:
> > I need to create a simple Yes/No select element, but am doing something
> > wrong and QF is creating the element with the number of options doubled
> > (Yes / No / Yes / No).
>
> Constructors of elements are actually called *twice*. This is an
> unfortunate design decision that cannot be fixed in current major
> version of QuickForm.
For those who would like to know why:
The constructor is called once on instantiation and once in
onQuickFormEvent. The instantiation call has *no parameters*, so all
parameters to the constructor must have defaults. After instantiation,
QF calls onQuickFormEvent on the element with a 'createElement' event.
The default version of onQuickFormEvent calls the constructor when a
'createElement' event occurs.
You can use this to your advantage by checking to see if there are any
arguments to tell when the element is instantiated vs. populated.
>
> You can work around this issue by checking whether the options were
> already set and not passing them again in this case.
>
> > Following is my class;
> >
> > class yesNo extends HTML_QuickForm_select {
> >
> > function yesNo(){
> > $options = array('1' => 'Yes',
> > '0' => 'No'); $data =
> > func_get_args();
> > parent::HTML_QuickForm_select($data[0], $data[1], $options);
> >
> > }
> > }
>
--
Justin Patrin