template::data::transform::search (public)

 template::data::transform::search element_ref

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

Process a submitted search widget's data.

Parameters:
element_ref (required)
Reference variable to the form element
Returns:
Transformed value

Partial Call Graph (max 5 caller/called nodes):
%3 db_list_of_lists db_list_of_lists (public) template::element::set_error template::element::set_error (public) template::data::transform::search template::data::transform::search template::data::transform::search->db_list_of_lists template::data::transform::search->template::element::set_error

Testcases:
No testcase defined.
Source code:

    upvar $element_ref element
    set element_id $element(id)

    set value [ns_queryget $element_id]

    # there will no value for the initial request or if the form
    # is submitted with no search criteria (text box blank)
    if {$value eq {}} { return [list] }

    if {$value eq ":search:"} {
        if { [info exists element(options)] } {
            unset element(options)
        }
        template::element::set_error $element(form_id) $element_id  "Please enter a search string."
        return [list]
    }

    # check for a value that has been entered rather than selected
    if { ! [ns_queryexists $element_id:select] } {

        # perform a search based on the value
        if { ! [info exists element(search_query)] } {
            error "No search query specified for search widget"
        }

        set query $element(search_query)

        set options [db_list_of_lists get_options $query]

        set option_count [llength $options]

        if { $option_count == 0 } {

            # no search results so return text entry back to the user

            if { [info exists element(options)] } {
                unset element(options)
            }

            template::element::set_error $element(form_id) $element_id  [subst {No matches were found for "[ns_quotehtml $value]".<br>Please\ntry again.}]

        } elseif$option_count == 1 } {

            # only one option so just reset the value
            set value [lindex $options 0 1]

        } else {

            # need to return a select list
            set element(options) [concat $options { { "Search again..." ":search:" } }]
            template::element::set_error $element(form_id) $element_id  [subst {More than one match was found for "[ns_quotehtml $value]".<br>
                    Please choose one from the list.}]

            set value [lindex $options 0 1]
        }
    }

    if { [info exists element(result_datatype)]
         && [ns_queryexists $element_id:select] } {
        set element(datatype) $element(result_datatype)
    }

    return [list $value]
XQL Not present:
PostgreSQL, Oracle
Generic XQL file:
packages/acs-templating/tcl/widget-procs.xql

[ hide source ] | [ make this the default ]
Show another procedure: