Help with extending HTML_QuickForm_select
| From: | Jamie Alessio | Date: | Sat, 05 Feb 2005 00:52:54 +0000 |
| Subject: | Help with extending HTML_QuickForm_select | ||
| Groups: | php.pear.dev | ||
| Request: | Send a blank email to pear-dev+get-35951@lists.php.net to get a copy of this message | ||
I'm working on implementing an HTML_QuickForm element for an "advanced multiple select". Basically, instead of having to ctrl+click items in a multselect it displays two multselect boxes side by side and allows you to move items between the two boxes (example at http://jalessio.com/pear/advmultselect.php).
I'm using javascript to handle moving the data between the multselect boxes. Presently, the only way to get the selected items into the $_REQUEST array upon form post is to add a javascript function call to the <form> tag so it looks something like this:
<form action="test.php" method="post"
onsubmit="javascript:myJsFunction(blah);">
The javascript is not a problem, but this requires that I add the "onsubmit" attribute to the <FORM> tag and I'm struggling with how to properly do this within the structure of HTML_QuickForm. As far as I can tell the only chance that a class that extends HTML_QuickForm has to modify the attributes of the the <FORM> tag is via the $caller variable in the onQuickFormEvent($event, $arg, &$caller) method in my inherited class. The only way I have gotten this to work so far is by catching when onQuickFormEvent() is called with an 'addElement' event and doing something like this:
$caller->updateAttributes(array(
'onsubmit' => "javascript: myJsFunction(blah)"));
Is this a *correct* way to do this? Can I reliably count on being able to set this during the 'addElement' event? Any thoughts on a better way to have a subclass of HTML_QuickForm modify the attributes of the <FORM> tag that the element is going to be a member of?
You can view an example of how this is currently working at http://jalessio.com/pear/advmultselect.php and please let me know if you have any problems with this in your browser of choice.
Thanks for any ideas.
- Jamie