PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » HTML » HTML_QuickForm » Bug #4611

AutoComplete JavaScript not being inserted for elements in groups

Details

Submitted2005-06-16 17:49 UTC
Fromrsleevi at networkstreaming dot com
Assignedavb
StatusClosed
PackageHTML_QuickForm
PHP Version4.3.11
OSIrrelevant
Roadmaps(Not assigned)

Comments

[2005-06-16 17:49 UTC] rsleevi at networkstreaming dot com

Description:
------------
When using the ArrayRenderer family of renderers, which includes the Smarty ArrayRenderer, rendering a group to HTML only inserts the Autocomplete JavaScript in the group's HTML, not the individual elements HTML.

This only affects people who are then accessing the internal elements HTML, rather than the group, and just using the addGroup() as a means of providing access from static templating engines to the variables.

Reproduce code:
---------------
$group[] = & $this->createElement('text', 'Field1', 'Field 1: ', null);
$group[] = & $this->createElement('autocomplete', 'Field2', 'Field 2: ', array('Option1', 'Option2'), null);

$myGroupElement = & $this->addGroup($group, 'myGroup', '', '', true);

/* Create smarty object at some point here, or any Array renderer */
$renderer = & new HTML_QuickForm_Renderer_ArraySmarty($smarty);
$this->accept($renderer)
$smarty->assign('form', $renderer->toArray());

The call stack flows like this:
call ->accept on the renderer, which then begins looping through the elements, passing the ->accept down which:
calls ->accept on the group, which
calls ->startGroup (in my case, in ArraySmarty) which
calls ->startGroup (in Array) which
calls ->_elementtoarray() which, if the type is group,
calls ->toHtml() on the group

This begins a loop through the elements within the group, for which the autocomplete is one of them. At this point, the constant HTML_QUICKFORM_AUTOCOMPLETE_EXISTS is not defined, so in the html for the autocomplete, the javascript gets added. All of this is combined to create the groups HTML entry in the array.

At this point, the group has completed ->startGroup(), and begins looping through elements, calling their ->accept() methods, which in turn call their ->toHtml() methods. This time, when the autocomplete fires ->toHtml(), it sees that the constant HTML_QUICKFORM_AUTOCOMPLETE_EXISTS is true (because it was set to true during the ->startGroup) and thus does not include the JavaScript.

Expected result:
----------------
{$form.myGroup.Field2.html} within the Smarty template returns the JavaScript autocomplete options and code to set them, and the code for the textbox to display

or

{$form.javascript} contains the AutoComplete JavaScript code (along with any client-side validators) and the elements .html just contains the options CDATA and the HTML for the element.

Actual result:
--------------
{$form.myGroup.html} contains the JavaScript autocomplete code, but {$form.myGroup.Field2.html} does not