Index: openacs-4/packages/xowiki/tcl/form-field-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/xowiki/tcl/form-field-procs.tcl,v diff -u -r1.102 -r1.103 --- openacs-4/packages/xowiki/tcl/form-field-procs.tcl 29 Sep 2008 01:38:19 -0000 1.102 +++ openacs-4/packages/xowiki/tcl/form-field-procs.tcl 29 Sep 2008 10:23:52 -0000 1.103 @@ -447,9 +447,13 @@ if {[my exists $var] && [my set $var] eq $value} {return 1} return 0 } - FormField instproc process_user_input {} { + FormField instproc convert_to_internal {} { # to be overloaded } + FormField instproc convert_to_external {value} { + # to be overloaded + return $value + } FormField instproc field_value {v} { if {[my exists show_raw_value]} { @@ -538,7 +542,7 @@ file instproc entry_name {value} { return [list name file:[my name] parent_id [[my object] item_id]] } - file instproc process_user_input {} { + file instproc convert_to_internal {} { my instvar value if {[my value] eq ""} { @@ -717,18 +721,34 @@ # ########################################################### - Class numeric -superclass text \ - -extend_slot validator numeric + Class numeric -superclass text -parameter { + {format %.2f} + } -extend_slot validator numeric numeric instproc initialize {} { next my set widget_type numeric + # check, if we we have an integer format + my set is_integer [regexp {%[0.9.]*d} [my format]] } + numeric instproc convert_to_external value { + if {$value ne ""} {return [lc_numeric $value [my format] [my locale]]} + return $value + } + numeric instproc convert_to_internal {} { + if {[my value] ne ""} { + set value [lc_parse_number [my value] [my locale] [my set is_integer]] + my set __refresh_instance_attributes [list [my name] $value] + return + } + } numeric instproc check=numeric {value} { - #return [string is double $value] - #my msg "locale=[my locale] catch {lc_parse_number $value [my locale]}=[catch {lc_parse_number $value [my locale]}]" - return [expr {[catch {lc_parse_number $value [my locale]}] == 0}] + return [expr {[catch {lc_parse_number $value [my locale] [my set is_integer]}] == 0}] } + numeric instproc pretty_value value { + return [my convert_to_external $value] + } + ########################################################### # # ::xowiki::formfield::user_id @@ -1693,9 +1713,9 @@ return 0 } - CompoundField instproc process_user_input {} { + CompoundField instproc convert_to_internal {} { foreach c [my components] { - $c process_user_input + $c convert_to_internal } } Index: openacs-4/packages/xowiki/tcl/xowiki-www-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/xowiki/tcl/xowiki-www-procs.tcl,v diff -u -r1.180 -r1.181 --- openacs-4/packages/xowiki/tcl/xowiki-www-procs.tcl 29 Sep 2008 01:38:19 -0000 1.180 +++ openacs-4/packages/xowiki/tcl/xowiki-www-procs.tcl 29 Sep 2008 10:23:52 -0000 1.181 @@ -671,14 +671,14 @@ #my msg "set form_value to form-field $att __ia($att)" if {[info exists __ia($att)]} { #my msg "my set_form_value from ia $att $__ia($att)" - my set_form_value $att $__ia($att) + my set_form_value $att [$f convert_to_external $__ia($att)] } else { # do we have a value in the form? If yes, keep it. set form_value [my get_form_value $att] #my msg "no instance attribute, set form_value $att '[$f value]' form_value=$form_value" if {$att eq ""} { # we have no instance attributes, use the default value from the form field - my set_form_value $att [$f value] + my set_form_value $att [$f convert_to_external [$f value]] } } } @@ -773,20 +773,6 @@ } # - # Postprocess based on form fields based on form-fields methods. - # Postprocessing might force to refresh some values in __ia() - # - foreach f $form_fields { - $f process_user_input - if {[$f exists __refresh_instance_attributes]} { - #my msg "refresh [$f set __refresh_instance_attributes]" - foreach {att val} [$f set __refresh_instance_attributes] { - set __ia($att) $val - } - } - } - - # # The first round was a processing based on the transmitted input # fields of the forms. Now we use the formfields to complete the # data and to validate it. @@ -839,6 +825,23 @@ incr validation_errors } } + + if {$validation_errors == 0} { + # + # Postprocess based on form fields based on form-fields methods. + # Postprocessing might force to refresh some values in __ia() + # + foreach f $form_fields { + $f convert_to_internal + if {[$f exists __refresh_instance_attributes]} { + #my msg "refresh [$f set __refresh_instance_attributes]" + foreach {att val} [$f set __refresh_instance_attributes] { + set __ia($att) $val + } + } + } + } + #my msg "--set instance attributes to [array get __ia]" my instance_attributes [array get __ia] my array set __ia [my instance_attributes] @@ -1032,12 +1035,12 @@ __* {} _* { set varname [string range $att 1 end] - $f value [my set $varname] + $f value [$f convert_to_external [my set $varname]] } default { if {[info exists __ia($att)]} { #my msg "setting $f ([$f info class]) value $__ia($att)" - $f value $__ia($att) + $f value [$f convert_to_external $__ia($att)] } } } @@ -1214,13 +1217,13 @@ switch -- $var { detail_link { set f [my lookup_form_field -name $var $form_fields] - $f value $value + $f value [$f convert_to_external $value] } title - text - description { set f [my lookup_form_field -name _$var $form_fields] } } - $f value $value + $f value [$f convert_to_external $value] } } }