template::widget::date (public)

 template::widget::date element_reference tag_attributes

Defined in packages/acs-templating/tcl/date-procs.tcl

Create a date entry widget according to a format string The format string should contain the following fields, separated by / \ - : . or whitespace:

stringmeaning
YYYY4-digit year
YY2-digit year
MM2-digit month
MONmonth name, short (i.e. "Jan")
MONTHmonth name, long (i.e. "January")
DDday of month
HH1212-hour hour
HH2424-hour hour
MIminutes
SSseconds
AMam/pm flag
Any format field may be followed by "t", in which case a text widget will be used to represent the field. the array in range_ref determines interval ranges; the keys are the date fields and the values are in form {start stop interval}

Parameters:
element_reference (required)
tag_attributes (required)

Partial Call Graph (max 5 caller/called nodes):
%3 template::widget::time_of_day template::widget::time_of_day (public) template::widget::date template::widget::date template::widget::time_of_day->template::widget::date template::widget::timestamp template::widget::timestamp (public) template::widget::timestamp->template::widget::date _ _ (public) template::widget::date->_ template::util::date::get_property template::util::date::get_property (public) template::widget::date->template::util::date::get_property template::widget::merge_tag_attributes template::widget::merge_tag_attributes (public) template::widget::date->template::widget::merge_tag_attributes util::trim_leading_zeros util::trim_leading_zeros (public) template::widget::date->util::trim_leading_zeros

Testcases:
No testcase defined.
Source code:
    variable ::template::util::date::fragment_widgets

    upvar $element_reference element

    array set attributes  [::template::widget::merge_tag_attributes element $tag_attributes]

    set output "<!-- date $element(name) begin -->\n"

    if { ! [info exists element(format)] } {
        set element(format) [_ acs-lang.localization-formbuilder_date_format]
    }

    # Choose a pre-selected format, if any
    switch -- $element(format) {
        long     { set element(format) "YYYY/MM/DD HH24:MI:SS" }
        short    { set element(format) "YYYY/MM/DD"}
        time     { set element(format) "HH24:MI:SS"}
        american { set element(format) "MM/DD/YY"}
        expiration {
            set element(format) "MM/YY"
            set current_year [clock format [clock seconds] -format "%Y"]
            set current_year [expr {$current_year % 100}]
            set element(short_year_interval)  [list $current_year [expr {$current_year + 10}] 1]
            set element(help) 1
        }
    }

    # Just remember the format for now - in the future, allow
    # the user to enter a freeform format
    append output "<input type=\"hidden\" name=\"$element(name).format\" "
    append output "value=\"$element(format)\" >\n"

    # Prepare the value to set defaults on the form
    if { [info exists element(value)]
         && [template::util::date::get_property not_null $element(value)]
     } {
        set value $element(value)
        foreach v $value {
            lappend trim_value [util::trim_leading_zeros $v]
        }
        set value $trim_value
    } else {
        set value {}
    }

    # Keep taking tokens off the top of the string until out
    # of tokens
    set format_string $element(format)

    set tokens [list]

    if {[info exists attributes(id)]} {
        set id_attr_name $attributes(id)
    }

    while { $format_string ne {} } {

        # Snip off the next token
        regexp {([^/\-.: ]*)([/\-.: ]*)(.*)}  $format_string match word sep format_string
        # Extract the trailing "t", if any
        regexp -nocase $template::util::date::token_exp $word  match token type

        lappend tokens $token

        # Output the widget
        set fragment_def $template::util::date::fragment_widgets([string toupper $token])
        set fragment [lindex $fragment_def 1]

        if {[info exists id_attr_name] && $id_attr_name ne ""} {
            set attributes(id) "${id_attr_name}.${fragment}"
        }

        set widget [template::widget::[lindex $fragment_def 0]  element  $fragment  [lindex $fragment_def 2]  $type  $value  $element(mode)  [array get attributes]]

        if { [info exists element(help)] } {
            append output "<label for=\"$element(id).${fragment}\">[lindex $fragment_def 3] $widget</label>"
        } else {
            append output $widget
        }

        # Output the separator
        if {$sep eq " "} {
            append output "&nbsp;"
        } else {
            append output "$sep"
        }

    }

    append output "<!-- date $element(name) end -->\n"

    return $output
XQL Not present:
Generic, PostgreSQL, Oracle
[ hide source ] | [ make this the default ]
Show another procedure: