Clear questions and runnable code get the best and fastest answer |
|
PerlMonks |
Re: Adding fields to a form using Catalyst/TTby chargrill (Parson) |
on Oct 13, 2006 at 18:30 UTC ( [id://578200]=note: print w/replies, xml ) | Need Help?? |
I've recently been trying to do something extremely similar, only instead of it being a work project, it was purely to learn how to get Catalyst to play nicely with AJAX-y type stuff. Against the advice of some of the folks in #catalyst, I decided to use HTML::Prototype. Here are some of the changes I made to dynamically add a single form field using ajax and Catalyst. Note, I set up an observed field (text field) that, on change, would fire off the appropriate xhttpd request, as this was only a proof of concept for me. So, it's not 100% what you're looking to do, but may give you a head start. First, in my lib/application.pm
This loads the Catalyst::Plugin::Prototype plugin. Then, in my header.tt file, I had to have the following:
... which generates the javascript used elsewhere in the HTML page. Then, I created a new .tt file for each form field I wanted to insert:
Here, the div id "task_output_name" is what gets updated for this particular ajax call. And then in the .tt file that includes the .tt file above:
Further, I had to make sure I had the "newrow" method defined in my lib/application/Controller/Application.pm file:
This is example is taken from my work-in-progess (and as such probably isn't the best way to do things), is greatly simplified, and doesn't do much, but does handle creating the ajax request, using TT to generate some HTML based on a template I already had setup, and inserting the HTML into the <div> tag defined. It also probably won't work for you without some major tweaking, since I only extracted bits of what I've done (hopefully the right ones ;) ) and gone through it without completely checking to make sure the bits I've shown here are 100% what you need :) If you get stuck after this, try going to this url, which is where I got started with it. Happy catalysting, --chargrill
In Section
Seekers of Perl Wisdom
|
|