Forum OpenACS Development: Re: Simple page using ad_form and -on_refresh

Collapse
Posted by Nis Jørgensen on
For the record, I have created the below patch that allows for setting form values in on_refresh. I haven't tested all the posibilities - just a test form to see that it "works" for my simple test case.

Please note that part of this code is just magical incantations to me. I have a feeling ad_form could use a little refactoring ... I might get around to that the next time it bites me.
Index: form-processing-procs.tcl
===================================================================
RCS file: /usr2/cvsroot/mlm/packages/acs-tcl/tcl/form-processing-procs.tcl,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 form-processing-procs.tcl
--- form-processing-procs.tcl  21 Apr 2004 09:15:40 -0000      1.1.1.1
+++ form-processing-procs.tcl  11 Nov 2004 18:31:37 -0000
@@ -989,6 +989,25 @@

        if { [info exists on_refresh] } {
            ad_page_contract_eval uplevel #$level $on_refresh
+
+            # NAJ: If values are set in the on_refresh block, stuff them into the form fields.
+            # This code is just a copy-paste (and a little gluing) of code from the other branches
+            # I don't understand the datas structures well enough to know if there is an easier way to
+            # do this - or if I am doing it in a foolproof way.
+
+            foreach element_name $af_element_names($form_name) {
+                if { [llength $element_name] == 1 } {
+                    if { [uplevel \#$level [list info exists $element_name]] } {
+                        set myvalues [uplevel \#$level [list set $element_name]]
+                        if { [info exists af_flag_list(${form_name}__$element_name)] && \
+                            [lsearch $af_flag_list(${form_name}__$element_name) multiple] >= 0 } {
+                            template::element set_values $form_name $element_name $myvalues
+                        } else {
+                            template::element set_value $form_name $element_name $myvalues
+                        }
+                    }
+                }
+            }
        }
    }

===================================================================

Collapse
Posted by Jade Rubick on
Nis: you might want to submit this in bug-tracker, to make sure it gets applied.
Collapse
Posted by Nis Jørgensen on
Hmm - the patch has problems with some existing form widgets. I don't have time to track this down now.

So don't use this at home.