Index: openacs-4/packages/acs-templating/tcl/data-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-templating/tcl/data-procs.tcl,v diff -u -N -r1.23.2.2 -r1.23.2.3 --- openacs-4/packages/acs-templating/tcl/data-procs.tcl 26 Apr 2019 10:56:47 -0000 1.23.2.2 +++ openacs-4/packages/acs-templating/tcl/data-procs.tcl 7 Oct 2019 13:54:58 -0000 1.23.2.3 @@ -38,6 +38,7 @@ @see template::data::validate::timestamp @see template::data::validate::time_of_day @see template::data::validate::url + @see template::data::validate::oneof } { return [validate::$type $value_ref $message_ref] @@ -518,6 +519,42 @@ return [template::util::date::validate $value message] } +ad_proc -public template::data::validate::oneof { + value_ref + message_ref +} { + Checks whether the submitted value is contained in the list of values provided via + the "-options" paramater of "::template::element::create". If the + paramter "-options" is not set on the element, the value is validated as "text". + + @param value_ref Reference variable to the submitted value + @param message_ref Reference variable for returning an error message + + @see template::element::create + @see template::data::validate::text + + @return True (1) if valid, false (0) if not +} { + + upvar 2 $message_ref message $value_ref value element element values values + + # Note: Parameter "-options" is a list containing two-element lists + # in the form { {label value} {label value} {label value} ...} + if {[info exists element(options)] } { + if {[lsearch -index 1 $element(options) $value] == -1} { + + set message "[_ acs-templating.Invalid_choice] \"[ns_quotehtml $value]\"" + return 0 + } + } else { + ad_log Warning "template::element::validate::oneof: Parameter \"-options\"\ + not specified for element \"$element(name)\" in form\ + \"$element(form_id)\". All user submitted input will be accepted!" + } + + return 1 +} + # Local variables: # mode: tcl # tcl-indent-level: 4