ZendX_JQuery_View_Helper_AjaxLink Doesn’t Handle “append”

Zend’s extra JQuery package has a nice helper you can use to create ajax links, but it can only update a container that you give it.

ajaxLink("Add Item",
array('update' => '#my-list'));

This doesn’t work to well if you want to create a list of N items…

Instead of bugging Zend to fix this (There aren’t doing any more additions to the 1.X series), I just added the following to line 202 of AjaxLink.php:

// Add an append option to AjaxLink - Brian
else if(!empty($options['append']) && is_string($options['append'])){
$updateContainer = $options['append'];
$callbackCompleteJs[] = sprintf('%s("%s").append(data);', $jqHandler, $updateContainer);

Wala, now you can use jQuery’s append function:

ajaxLink("Add Item",
array('append' => '#my-list'));

Leave a Reply

Your email address will not be published. Required fields are marked *