Forum OpenACS Q&A: category::ad_form::* possible improvement

Hello everyone,

I am trying to build a smooth development workflow which will hopefully save me as much coding as possible.

With this idea in mind, I am trying to exploit category::ad_form::* functionalities, to give categorization to my plain acs_objects easily.

Referring to packages/xotcl/generic-procs, we can see that ::Generic::Form embeds this feature when the flag 'with_categories' is specified.

I have successfully applied this feature by mapping a tree to my application package, then using a ::Generic::Form to map a category to my object. The mapping has succeded, as I can verify by querying manually, but when I use the form again, the dropdown list for category is empty: mapped category value is not read from the object and put into form widget, as it may seem.

Am I doing something wrong or there is a little step missing here?

Investigating on my istallation, I've tried creating a procedure called 'category::ad_form::read_categories' that should be put into the edit_request section of an ad_form. The proc reads mapped categories for the objects and sets the proper form fields so the value can be shown. This fixes the issue for me.

Sounds legit?

Collapse
Posted by Antonio Pisano on
Recapping the issue:

when I create a new object, I can successfully map it to one or more categories using category::ad_form::* machinery.

Documentation for this feature is here: http://www.openacs.org/doc/tutorial-categories.html

However, when I am using the form to edit an existing object, nothing is done to retrieve its category mappings and use them to fill category widgets that are auto-generated. The widget will always be empty, despite the existance of category mappings.

I have filled this gap by adding a procedure called 'category::ad_form::fill_widgets' (refactoring the one from previous message), used to enhance ad_form's edit_request.

I have then applied this proc into ::Generic::Form to the portion in which category management is embedded, so I can use it to categorize my objects.

The change suits for me. I have tested with xotcl-demo-note application to ensure previous logic wouldn't break, so I feel enough confident to commit. The change is extensively commented in the code, so people can trace my reasons.

Best regards