Forum OpenACS Development: Re: ad_form for new and edit requests

Collapse
Posted by Don Baccus on
I personally don't see the utility in listing out each possible state rather than listing parallel interacting states independently.

In other words, a submitted form either has errors, or it doesn't, and it doesn't matter if it's a from meant to add a new record or edit an existing one.  In either case the form's  filled with data and error messages which you are intended to edit.  Saying "this is a new form", "this is a new form with errors", "this is an edit form", etc seems more confusing than breaking things down to their fundamentals.

The basic steps in the template form builder, exposed by ad_form, are:

1. Build the initial form, with or without existing data.

2. Submit and verify the form, repeating step one and two with the submitted data if there are errors.

3. Do something with the verified data that has been posted, with new_data and edit_data being shortcuts when the database is involved.

Display mode complicates things.  Forms which display some fields and allow for entry of others complicates things further.  For basic understanding I think both concepts should be avoided in initial documentation and added as "advanced ad_form hacking".

Collapse
Posted by Joel Aufrecht on
My purpose in going to a greater level of detail is that I feel ad_form is currently a "leaky abstraction." It hides details, but not consistently enough, so that its behavior is unpredictable. For example, I wrote code that behaved worked fine until a data field didn't validate, and then ad_form was essentially in a new mode, and it crashed. So I want to drive down past the abstraction, make sure we get it right, and then come back up with a tighter abstraction.

Re: display mode - I think we should go in the opposite direction. That is, we should use ad_form as the recommended, simplest method of displaying single records in detail view. My reasoning is, it's most of the way there already and it's the right approach. The logic for determining which fields to display and in what mode is usually very similar for both edit and display mode. And while ad_form is already pretty complicated, I think that's because of its history and because it's stuck in-between - in particular, in between functional style and declarative style. In some parts you simply describe what you want to see, and in others you have to know the right order of things and what will and won't get pre-processed and when.

Another approach I want to put on the table is creating ad_form2, where we take the best of ad_form and take a clean conceptual approach.

Please see my post earlier in this thread for an enumeration of things I think we should be able to do with ad_form.