template::widget::h5date (public)

 template::widget::h5date element_reference tag_attributes

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

Implements the HTML 5 input type "date". Supported element parameters: "-min" and "-max": for setting minimum and maximum dates that can be chosen by the user. If used, the condition min <= value <= max must be met. (Format = YYYY-MM-DD) "-step": number of days jumped each time the date is incremented. Value must be an integer Parameters supplied this way will supersede same-named parameters supplied through the "-html" switch. This widget also adds the attribute "pattern" as fallback for browsers which do not support input type="date".


Partial Call Graph (max 5 caller/called nodes):
%3 template::widget::input template::widget::input (public) template::widget::h5date template::widget::h5date template::widget::h5date->template::widget::input

No testcase defined.
Source code:
    upvar $element_reference element

    set attributes [dict create]

    # attributes supplied via -html switch
    if { [info exists element(html)] } {
        dict set attributes {*}$element(html)

    if {[llength $tag_attributes] > 0} {
        dict set attributes {*}$tag_attributes

    # Add fallback pattern attribute. Note that this pattern won't
    # account for leap years or invalid days of the month. We leave
    # this fine-graned validation to the server-side for now.
    dict set attributes pattern {[0-9]+-(1[0-2]|0[0-9])-(3[0-1]|[0-2][0-9])}

    # check min/max constraint
    set last_date ""
    foreach d {max value min} {

        if {[info exists element($d)] && $element($d) ne ""} {
            set attr_value $element($d)
        } elseif {[dict exists attributes $d] && [dict get $attributes $d] ne ""} {
            set attr_value [dict get $attributes $d]
        } else {

        set invalid_date_p [catch {
            set current_date [clock scan $attr_value -format "%Y-%m-%d"]

        if {!$invalid_date_p} {
            if {$last_date ne "" &&
                $current_date > $last_date} {
                ns_log Warning "template::widget::h5date value of attribute \"$d\" $attr_value too big"
            } else {
                dict set attributes $d $attr_value

            set last_date $current_date

        } else {
            ns_log Warning "template::widget::h5date value of attribute \"$d\" $attr_value is not a correct date"

    if {[info exists element(step)]} {
        if {[string is integer -strict $element(step)]} {
            dict set attributes step $element(step)
        } else {
            ns_log Warning {template::widget::h5date value of attribute "step" is not an integer!}

    return [template::widget::input date element $attributes]
XQL Not present:
Generic, PostgreSQL, Oracle
[ hide source ] | [ make this the default ]
Show another procedure: