Hello,

I need some help with a module I'm developing. Before anything, I want to say that I have searched the forums and looked after existing modules for this, but I've found nothing.

It's a module for loading the node create/edit form via ajax in a custom div, but I'm having some problems. The objective is to integrate it with the views module, so everytime I click in the edit node link provided in the view, I can edit the node in the form loaded below the view, without an entire page reload, and without losing all the view data.

Right now, I have managed to return the form with AJAX and load it in the page. It's functional in the way that I can fill the title and body sections, and press submit so the node gets saved in the database, but the collapsable elements in the form don't appear correctly (publishing options, input formats, authoring options, etc). These elements are not showing like collapsable elements, but as plain text instead.

Here is an image so you can see how is displaying the form after it's returned via AJAX. (with the collapsable items as plain text):

http://img855.imageshack.us/i/formularioajax.jpg/

Right now I'm making the AJAX call with a custom text link and the ".load(url)" function of jQuery. The URL I'm using is the one for which I have declared a callback function with hook_menu(). That function is generating the form and returning it to the client, like this (for testing purposes, with the story content type form):

function ajaxnodeform_get_form() {
	$node_form = node_add('story');
	print $node_form;
}

I have tried with other functions, like drupal_json(), simple "return $node_form", and many more, as well as other hooks and drupal functions, but none of them has worked for me.

I suppose the problem is that I'm not returning well formated the form, but I dont know if it needs more manage before returning it to the client. Besides of this, I don't know if I have to use another function instead of the "print $node_form" to return correctly the form, or I have to use another Javascript function instead of ".load(url)".

Hope you can help me please, as this is becoming a bit of a headache.

Comments

slv_’s picture

I'm still jammed here. Any advice?

Thanks!

--author="slv "

eileen’s picture

I hope maybe bumping your topic might inspire a brilliant and generous coder to chime in with some helpful advice?

Or, did you ever get it working?

d0t15t’s picture

subscribe

paganwinter’s picture

As far as I can tell, the collapsible elements not showing up right is because they are made collapsible by javascript code that is called when those elements are added on the page.

To recreate the effect you are getting, turn off javascript on your browser and try loading a node creation page. It should look identical to what you are seeing.

This is how the actual form page works:
The form is displayed on the page.
After the page loads, events are attached to the collapsible elements through javascript.

What you need to do is, manually call the javascript function which attaches these events, using the call back argument of the .load() function.

Go through these documentations: http://drupal.org/node/121997 and read up about Drupal.behaviors