-- MarkDNA <[EMAIL PROTECTED]> wrote
(on Friday, 31 October 2008, 06:23 PM -0700):
> I am attempting to do an "in-line editing" solution that has dijit elements
> declared in a form that then have an xhrPost action that updates the data
> and returns the form again. The problem that I'm encountering is that when
> the div is returned, the form elements are no longer "Dojo-ized" - they are
> plain html form elements. When I first hit the page, the elements are
> created and display properly, it's just after the xhrPost that I am having
> issues. The end of my xhrPost action is like this:
> 
> $this->view->lineItems = $lineItems->toArray();
> $this->view->info = $invoice->toArray();
> $this->_helper->layout->disableLayout();
> 
> $this->view->addHelperPath('Zend/Dojo/View/Helper/',
> 'Zend_Dojo_View_Helper');
> Zend_Dojo::enableView($this->view);
> $this->render('editLineItemsPartial');
> 
> I've tried various variations, and I can't seem to get the partial to render
> correctly after it hits this action. I've also tried to activate dojo in the
> partial, but that doesn't seem to work either. Any suggestions?

I'm assuming you're returning HTML markup in response to the XHR
request, so if that's not the case, you'll need to give more details.

First, you need to make certain that the originating page has all the
necessary dojo.require statements for any of the form elements that may
return via the XHR call; otherwise, you'll run into parse errors. I
typically create a custom layer that declares these -- that way I have a
single place to update them, and I can also create a custom build layer
in order to optimize the performance of the application. 

Second, for XHR requests, I always have my view use declarative Dojo
syntax:

    Zend_Dojo_View_Helper_Dojo::setUseDeclarative();

This ensures that you can run the dojo parser over the returned markup.
Returning and executing Javascript from XHR is often considered a
security issue, and can additionally be difficult to get to work
correctly.

This leads to my third point: you'll need to run the dojo parser again
*after* you've inserted the new HTML into your DOM. This is done with
the following call:

    dojo.parser.parse();

You can actually run the parser on a containing node as well. So, if
you did something like the following with the response payload:

    var formContainer = dojo.byId('form-container');
    formContainer.innerHTML = data;

then you'd call this immediately following:

    dojo.parser.parse(formContainer);

Hope that helps answer your question!

-- 
Matthew Weier O'Phinney
Software Architect       | [EMAIL PROTECTED]
Zend Framework           | http://framework.zend.com/

Reply via email to