[Catalyst] Ajax, Jemplate, forms, rest & data validation

J. Shirley jshirley at gmail.com
Sat May 24 00:20:52 BST 2008


On Fri, May 23, 2008 at 3:10 PM, Henry Drinkwater
<henry.drinkwater at googlemail.com> wrote:
> Hi,
>
> I'm new to Catalyst so apologies if this is a dumb question. I'm working on
> a web site using Catalyst and want to use quite a bit of Ajax interactivity
> to make the site as user friendly and modern as possible. The majority of my
> knowledge of Catalyst comes from the Jonathon Rockway book, so I have so far
> been concentrating on using Jemplate for the AJAX, and using a REST
> interface to handle the data serialization.
>
> This is working very nicely for the retrieve/get part, but I am struggling a
> bit to figure out the best way of handling forms and the submission &
> validation of the data. The formbuilder controller makes it incredibly
> simple to build and validate a form, on both the client and the server, and
> I want to have similar functionality but AJAX enabled - i.e. I envisage the
> form submission method being a PUT to a REST controller, and for the
> submission to cause a div to be updated in place, rather than a load of a
> new page.
>
> In the book the example uses a POST to a pre-existing formbuilder controller
> as the submission method of the ajax form, which is neat in that it handles
> the data validation part without writing any code, but not so good in that
> it is not really ajax-y, as it results in loading a new page. The book also
> mentions putting data validation into the Model and not in the controller,
> which I guess would work fine but will require quite a bit more code to be
> written. I'd rather not have to write the validation myself if there's a
> good module out there which would do it for me, based on the form
> definition.
>
> So I'm looking for recommendations as to how to handle this - would I be
> better taking the time to learn one of the javascript libraries (e.g. YUI or
> Dojo) and moving away from Jemplate, or is there a way to combine
> formbuilder and Jemplate in a more dynamic ajax-y way? If anyone has any
> suggestions for other tutorials or example code I could look at to get more
> ideas of how to do this, I'd be very grateful.
>
> regards,
> Henry
>
> ps I have been following the thread on RFC: Catalyst::Controller::REST::DBIC
> on the list, which seems to be talking about stuff along these lines, but I
> haven't really gleaned any ideas on how best to tackle this. I also found
> Jay Shirley's slides on "No REST for the Wicked: Catalyst, REST and YUI"
> which sounded very relevant, but again I didn't learn enough to really get
> me coding.
>
> pps I found the book incredibly helpful, once I found the errata web site
> and got past chapter 3. It got me very quickly over the learning curve on
> Catalyst and writing real code.
>
> _______________________________________________
> List: Catalyst at lists.scsys.co.uk
> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
> Dev site: http://dev.catalyst.perl.org/
>
>


Henry,

At this point I'd advise you to look through the examples/ dir in the
Catalyst SVN and you'll get more applicable knowledge.

http://dev.catalystframework.org/repos/Catalyst/trunk/examples/

My talk on REST coincides with principles that are coded up in
http://dev.catalystframework.org/repos/Catalyst/trunk/examples/RestYUI
(although the application name is AdventREST, it is modified from the
original Advent calendar entry to work with YUI).

On the validation note, I use Data::FormValidator in conjunction with
a DBIx::Class ResultSet - still in the model, in that it is outside of
the Catalyst scope.  Easier to unit test this stuff, too, since you
don't have to muck with a controller.  Lots of other folk use
FormBuilder or FormFu, so it is really just picking what makes the
most sense to you.

Good luck,
-J



More information about the Catalyst mailing list