Index: openacs-4/packages/acs-core-docs/www/form-builder.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-core-docs/www/form-builder.adp,v diff -u -r1.3 -r1.4 --- openacs-4/packages/acs-core-docs/www/form-builder.adp 8 Nov 2017 09:42:10 -0000 1.3 +++ openacs-4/packages/acs-core-docs/www/form-builder.adp 25 Apr 2018 08:38:27 -0000 1.4 @@ -3,11 +3,11 @@ Using Form Builder: building html forms dynamically -
+ leftLink="programming-with-aolserver" leftLabel="Prev" + title="Chapter 11. Development +Reference" + rightLink="eng-standards" rightLabel="Next"> +

Using Form Builder: building html forms dynamically

@@ -25,10 +25,10 @@ Multi-part Elements

Some elements have more than one choice, or can submit more than one value.

-SELECT elements

  1. +SELECT elements
  1. -Creating the form element.  -Populate a list of lists with values for the option list.

    +Creating the form element.  Populate a
    +list of lists with values for the option list.

     set foo_options [db_list_of_lists foo_option_list "
         select foo,
                foo_id
    @@ -37,12 +37,10 @@
     

    The variable foo_options should resemble {{first foo} 1234} {{second foo} 1235} -

    Within ad_form, set up the element to use this list:

    -{foo:text(select)
    +

    Within ad_form, set up the element to use this list:

    {foo:text(select)
             {label "Which Foo"}
             {options $foo_options}
    -    }
    -

    This will result in a single name/value pair coming back in the + }

    This will result in a single name/value pair coming back in the submitted form. Handle this within the same ad_form structure, in the -new_data and -edit_data. In the example, it is available as $foo @@ -57,29 +55,25 @@ form items from a sub-category when the first category is selected. Ad_form makes this fairly easy to do. In the definition of your form element, include an html section

    -    {pm_task_id:integer(select),optional
    +{pm_task_id:integer(select),optional
             {label "Subject"}
             {options {$task_options}}
             {html {onChange "document.form_name.__refreshing_p.value='1';submit()"}}
             {value $pm_task_id}
         }
    -    
    -

    What this will do is set the value for pm_task_id and all the +

    What this will do is set the value for pm_task_id and all the other form elements, and resubmit the form. If you then include a block that extends the form, you'll have the opportunity to add in subcategories:

    -    if {[info exists pm_task_id] && $pm_task_id ne ""} {
    +if {[info exists pm_task_id] && $pm_task_id ne ""} {
         db_1row get_task_values { }
         ad_form -extend -name form_name -form { ... }
    -    
    -

    Note that you will get strange results when you try to set the +

    Note that you will get strange results when you try to set the values for the form. You'll need to set them explicitly in an -on_refresh section of your ad_form. In that section, you'll -get the values from the database, and set the values as so:

    -    db_1row get_task_values { }
    +get the values from the database, and set the values as so:

        db_1row get_task_values { }
         template::element set_value form_name estimated_hours_work $estimated_hours_work
    -    
    -
    +

Troubleshooting

A good way to troubleshoot when you're using ad_form is to @@ -93,8 +87,7 @@ ns_log notice the following form was submitted on my page ns_set print $mypage } - - +

Tips @@ -106,14 +99,14 @@ Errors

Here are some common errors and what to do when you encounter them:

-Error when selecting values

This generally happens when there is an error in your query.

+Error when selecting values

This generally happens when there is an error in your query.

- \ No newline at end of file + leftLink="programming-with-aolserver" leftLabel="Prev" leftTitle="Programming with AOLserver" + rightLink="eng-standards" rightLabel="Next" rightTitle="Chapter 12. Engineering +Standards" + homeLink="index" homeLabel="Home" + upLink="dev-guide" upLabel="Up"> + \ No newline at end of file