Forum OpenACS Development: ad_form documentation

Collapse
Posted by Jon Griffin on
I put some docs on using ad_form at:
http://jongriffin.com/static/openacs/ad_form/using-ad- form

Please comment as this is just the beginning. I am sure some things are incomplete and maybe done wrong.

Collapse
Posted by Ola Hansson on
Jon, here is some feedback to start you off:

Elements take the form of:
element-name:type(widget)  # should probably be element_name 😉

You should say:

if {[ad_form_new_p -key category_id]} {
  ...

instead of:

if {[info exists category_id]} {

(and have the new and edit block switch location with one another)

Your current example will not show the correct title, etc., if validation fails, you know.

Should you mention that "-name new_category" in the -form block is optional..? I dunno, perhaps it's good to always specify a form name even though it's not always necessery.

And, I remember that I was held up for half an hour, not realizing that the following must be on one line:

} -select_query_name category_select -new_data {

It may be worth mentioning that...

Collapse
Posted by Tilmann Singer on
There's some info on ad_form_new_p in this thread:

https://openacs.org/bboard/q-and-a-fetch-msg.tcl?msg_id=0006YU

Note that within the -form declaration it's not necessary to continue lines with a backslash at the end. The list declarations can span several lines without a problem - emacs in tcl-mode indents them automatically quite nicely, like this:


    {start_date:date,to_sql(sql_date),from_sql(linear_date) 
        {label "Start"} 
        {format "YYYY/MM/DD HH12:MI AM"} 
        {minutes_interval {0 45 15}} 
        {today} 
        {help}}

And for the risk of being called a nitpicker again: I'd find it nice if the code was properly indented in the example - currently some of the widget declarations align to the left border but should be indented.

Having inline comments in the example would make it more readable too:

} -edit_data {
    # valid request to update an existing record
    db_exec_plsql note_update { }
    ad_returnredirect "."
    ad_script_abort
}
Collapse
Posted by defunct defunct on
Worth pointing out that you don't need the  due to Till's use of {} you do need it without (or at least thats what I get here)
Collapse
Posted by Don Baccus on
Ola, Simon, ad_form's cool but remember ... it's just Tcl :)  I can't banish the standard Tcl rules for parsing input just by writing a proc!

ad_form_new_p is a new proc written by Tilmann that works when there's a error in form validation, which confuses the simpler "info exists" test.  So, yes, the doc is out of date on this point.

For a complete list of datatypes, go to acs-templating/tcl and do

grep ::validate *.tcl

For a complete list of widgets, to go acs-templating/tcl and do

grep ::widget widget-procs.tcl

(ad_form knows nothing about widgets and datatypes beyond what the form templating system implements)

Collapse
Posted by defunct defunct on
Oh, I know that... just pre-empting the 'i took out my backslashes and it doesn't work now'.. posts ;)

*TCL Looney*, managed to use nothing else for 6 years now.. arf, dunno if thats TCL's a good tool, or its a damn site less hassle than *real* programming ;)

Collapse
Posted by Ola Hansson on
*Damn* I'm disappointed Tcl cannot read my mind and just do what I want it to, and not what I tell it.

What can I say - the (to me) completely new and totally cool lay-up of the different blocks of ad_form in the api-doc example must have overwhelmed me, making me totally dased and confused. Yeah, that must have been it! 😊

And it all works now! Isn't that strange?

Anyway, I think I personally prefer the following style:

} -select_query_name {
    category_select
} -new_data {
Collapse
Posted by Jon Griffin on
I updated the doc today.

It is still not 100% complete, but it should surely help anyone looking to use ad_form.

I am converting all my relevant docs to doc_book so please send me more comments and I will have this ready for the pending 4.6 release.