[html-formfu] Best approach for multiple item editing

Carl Franks fireartist at gmail.com
Tue Sep 30 13:23:16 BST 2008


2008/9/30 Nigel Metheringham <nigel.metheringham at dev.intechnology.co.uk>:
> Hi,
>
> I am currently refactoring an older Catalyst app, and in the process
> changing it from using HTML::Widget to HTML::FormFu.
>
> The parts of this that are relatively straight CRUD operations are nice
> and easy to do. However I'd like to get suggestions as to the best way
> of handling some of the less straightforward items.
>
> The Model for the app is a DBIx::Class stack.
>
> Generically, what I want to do is be able to add a mechanism for editing
> a whole batch of items on one form - the items are the result of a
> has_many relationship.
>
> Specifically I have an Event table (this contains data for name etc, as
> well as a start_date and end_date - the dates here are pure date (no
> time) fields inflated into DateTime).
>
> An Event has_many Bookings - these have a start_time and an end_time,
> which are also inflated into a DateTime although these do have time
> elements on them. [There is an unexpressed constraint on a Booking that
> the start_time and end_time must be on the same calendar day].
>
> I want to be able to have a Bookings edit form for an Event - giving me
> the chance to edit all the Bookings for a particular event (including
> adding/deleteing bookings).
>
> When trying this with HTML::Widget I had some horrid code in the
> Controller which generated up a form with a set of lines (one per
> Booking) with:-
>
>  -- Date pulldown - range limited by Event Date (plus blank/unselected)
>  -- Start time pulldown, 30 minute intervals across the day
>  -- End time pulldown, 30 minute intervals across the day
>
> For the case when first editing the Bookings for an Event the Model
> would generate a standard set of Bookings to bootstrap this. There were
> also a couple of additional sets of Booking lines over those currently
> used to allow additional bookings to be added.
>
> Given this sort of arrangement, how would you suggest I approach making
> a form to edit Bookings for an Event?
>
> [Some of this would better suit an AJAXy edit form I know, but I would
> like to have a basic HTML version before adding whizzy stuff. And if you
> are wondering what all this is for, its the bookings management stuff
> for a community theatre.]

You can do most of this already with a Repeatable block element, and
HTML::FormFu::Model::DBIC

See the test files in the HTML-FormFu-Model-DBIC for examples, specifically:
t/default_values/has_many_repeatable*
t/update/has_many_repeatable*

There's also support for a checkbox which deletes that row, if checked.

I have an example Catalyst application, which also supports adding new
rows by doing a round-trip to the server - but I'm not sure if it's
working at the moment, and unfortunately I won't have time this week
to look at it (and I'm on holiday next week) - but if you want a look
at it after that, give me a shout.

Btw, the HTML::FormFu::Model::DBIC documentation on cpan is horribly
out of date. It's been improved somewhat in svn, but is still missing
a lot.

Carl



More information about the HTML-FormFu mailing list