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.18 -r1.19 --- openacs-4/packages/xowiki/tcl/form-field-procs.tcl 15 Jul 2007 23:45:33 -0000 1.18 +++ openacs-4/packages/xowiki/tcl/form-field-procs.tcl 16 Jul 2007 22:43:35 -0000 1.19 @@ -60,25 +60,55 @@ return [_ acs-templating.Element_is_required] } # todo: value type checker (through subtypes, check only if necessary) + # + #my msg "[my name] [my info class] validator=[my validator]" if {[my validator] ne ""} { set errorMsg "" # # The validator might set the variable errorMsg in this scope. # - #my msg "call [my validator] '$value'" - set r [$obj validate=[my validator] $value] + set validator_method check=[my validator] + set proc_info [my procsearch $validator_method] + #my msg "[my name] [my info class] validator_method=$validator_method $proc_info" + if {$proc_info ne ""} { + #my msg "call field specific validator $validator_method '$value'" + set r [my $validator_method $value] + } else { + set validator_method validate=[my validator] + set proc_info [$obj procsearch $validator_method] + #my msg "call object level validator $validator_method '$value'" + set r [$obj $validator_method $value] + } if {$r != 1} { # # We have an error message. Get the class name from procsearch and construct # a message key based on the class and the name of the validator. # - set cl [namespace tail [lindex [$obj procsearch validate=[my validator]] 0]] + set cl [namespace tail [lindex $proc_info 0]] return [_ xowiki.$cl-validate_[my validator] [list value $value errorMsg $errorMsg]] } } return "" } + FormField instproc reset_parameter {} { + # reset application specific parameters (defined below ::xowiki::FormField) + # such that searchDefaults will pick up the new defaults, when a form field + # is reclassed. + for {set c [my info class]} {$c ne "::xowiki::FormField"} {set c [$c info superclass]} { + #my msg "[my name] parameters ($c) = [$c info parameter]" + foreach p [$c info parameter] { + set l [split $p] + if {[llength $l] != 2} continue + set var [lindex $l 0] + if {[my exists $var]} { + #my msg "[my name] unset '$var'" + my unset $var + } + } + } + } + FormField instproc config_from_spec {spec} { my instvar type options widget_type if {[my info class] eq [self class]} { @@ -119,14 +149,17 @@ default { if {[my isclass [self class]::$s]} { my class [self class]::$s + my reset_parameter + #my msg "[my name] searchDefaults" + ::xotcl::Class::Parameter searchDefaults [self]; # TODO: will be different in xotcl 1.6.* } else { #my msg "Ignoring unknown spec for entry [my name]: '$s'" error [_ xowiki.error-form_constraint-unknown_spec_entry [list name [my name] entry $s x "Unknown spec entry for entry '$s'"]] } } } } - ::xotcl::Class::Parameter searchDefaults [self]; # TODO: will be different in xotcl 1.6.* + # # It is possible, that a default value of a form field is changed through a spec. # Since only the configuration might set values, checking value for "" seems safe here. @@ -331,11 +364,29 @@ } FormField::text instproc initialize {} { my set widget_type text - foreach p [list size] {if {[my exists $p]} {my set html($p) [my $p]}} + foreach p [list size maxlength] {if {[my exists $p]} {my set html($p) [my $p]}} } ########################################################### # + # ::xowiki::FormField::numeric + # + ########################################################### + + Class FormField::numeric -superclass FormField::text -parameter { + {validator numeric} + } + FormField::numeric instproc initialize {} { + my validator numeric + next + my set widget_type numeric + } + FormField::numeric instproc check=numeric {value} { + return [string is double $value] + } + + ########################################################### + # # ::xowiki::FormField::textarea # ########################################################### @@ -381,8 +432,18 @@ if {[my editor] eq ""} { next } elseif {[my info class] ne "[self class]::[my editor]"} { - my class [self class]::[my editor] - ::xotcl::Class::Parameter searchDefaults [self]; # TODO: will be different in xotcl 1.6.* + set editor_class [self class]::[my editor] + if {![my isclass $editor_class]} { + set editors [list] + foreach c [::xowiki::FormField::richtext info subclass] { + lappend editors [namespace tail $c] + } + error [_ xowiki.error-form_constraint-unknown_editor \ + [list name [my name] editor [my editor] editors $editors]] + } + my class $editor_class + my reset_parameter + ::xotcl::Class::Parameter searchDefaults [self]; # TODO: will be different in xotcl 1.6.* my initialize } else { next Index: openacs-4/packages/xowiki/tcl/xowiki-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/xowiki/tcl/xowiki-procs.tcl,v diff -u -r1.141 -r1.142 --- openacs-4/packages/xowiki/tcl/xowiki-procs.tcl 15 Jul 2007 23:45:33 -0000 1.141 +++ openacs-4/packages/xowiki/tcl/xowiki-procs.tcl 16 Jul 2007 22:43:35 -0000 1.142 @@ -1255,8 +1255,8 @@ Form instproc validate=form_constraints {form_constraints} { # + # First check for invalid meta characters for security reasons. # - # if {[regexp {[\[\]]} $form_constraints]} { my uplevel [list set errorMsg [_ xowiki.error-form_constraint-invalid_characters]] return 0 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.77 -r1.78 --- openacs-4/packages/xowiki/tcl/xowiki-www-procs.tcl 16 Jul 2007 12:03:53 -0000 1.77 +++ openacs-4/packages/xowiki/tcl/xowiki-www-procs.tcl 16 Jul 2007 22:43:35 -0000 1.78 @@ -606,15 +606,6 @@ set form [lindex [my get_from_template form] 0] set anon_instances [my get_from_template anon_instances] - if {[my is_new_entry [my name]]} { - my set creator [::xo::get_user_name [::xo::cc user_id]] - my set nls_language [ad_conn locale] - if {!$anon_instances} { - my set title "" - my set name "" - } - } - if {$form eq ""} { # # Since we have no form, we create it on the fly @@ -688,6 +679,12 @@ # # display the current values # + + if {[my is_new_entry [my name]]} { + my set creator [::xo::get_user_name [::xo::cc user_id]] + my set nls_language [ad_conn locale] + } + array set __ia [my set instance_attributes] foreach att $field_names { switch -glob $att { @@ -704,7 +701,16 @@ } } } + set ff($att) $f } + + # for named entries, just set the entry fields to empty, + # without changing the instance variables + if {!$anon_instances && [my is_new_entry [my name]]} { + $ff(_title) value "" + $ff(_name) value "" + } + }