Dynamic content creation within the add/edit windows

Permalink
Howdy,
I'm looking for a way to create dynamic content within a block's add/edit window. If a user clicks on something like a "more" button, then an additional set of forms/wysiwyg/whatever my default content object is will be created and appear underneath the previous one(s). I have already achieved this using jQuery/foreign relationships in the database.

What I am wondering is if there's a way to have the "more" button hit my controller and then create my content object there (so have its creation PHP based rather than js). I would then like to send that back to the add/edit window without the window having to refresh (AJAX in my thinking...). I'm hoping by doing this I can use the $form helper/learn another technique for achieving what I have done.

I've seen the $BlockView->action() method, but does that work in the add/edit windows? It also looked like the add/edit window would have to refresh anyways with the href being set to the task within my controller. Not really sure how else to go about it. I'll stick with JS if I have to, but if anyone has any knowledge on this I'd love to get in on it!

Thanks for your time,

-Landson

Landson
 
JohntheFish replied on at Permalink Best Answer Reply
JohntheFish
You have to be careful with block actions in an add dialog because the block does not yet exist, so the action fails.

The dialog part of The Ajax Lessons addon shows this. The package or block tools dialog examples may give models you can follow. Personally I usually use package tools. I doubt if there is any real difference, but I find the overall structure less convoluted.
http://www.concrete5.org/marketplace/addons/ajax-lessons/...

I find the easiest jquery ajax method to use for this sort of thing is $().load().

If you need to use the block data in your tool, you can pass the bID with the ajax call and create a block instance within the tool. But again, this will only work for existing blocks and not during add.
Landson replied on at Permalink Reply
Landson
Thanks a ton, I'll delve into that pronto!
Landson replied on at Permalink Reply
Landson
That was extremely helpful John! Good eye opener for what I can do for my app! Thanks again!