Tk Library Source Code

Documentation
Login


[ Main Table Of Contents | Table Of Contents | Keyword Index | Categories | Modules | Applications ]

NAME

widget_validator - widget::validator behaviour

Table Of Contents

SYNOPSIS

package require Tcl 8.5
package require Tk 8.5
package require widget::validator ?0.1?

widget::validator attach w color cmdprefix
widget::validator detach w
widget::validator validate w

DESCRIPTION

This package provides a unified validation API for ttk's entry and combobox widgets.

Please note that the validation behaviour defined in this package will not reject invalid edits. It will only highlight the entry containing invalid data and set the proper state flag.

It is the responsibility of the using package or application to decide how and when to actually reject such invalid content.

Validation

The command prefix for used for validation has to have the following signature:

Example

package require Tk 8.5
package require widget::validator

set TE {}
set TC {}

ttk::entry    .e -textvariable TE
ttk::combobox .c -textvariable TC -values {fruit vegetable corn}
ttk::combobox .n -values {fruit vegetable corn}
ttk::button   .x -command ::exit -text Exit

pack .e -expand 1 -fill both -side top
pack .c -expand 1 -fill both -side top
pack .n -expand 1 -fill both -side top
pack .x -expand 1 -fill both -side top

widget::validator attach .e lightblue {apply {text {
    expr {$text ne {}}
}}}

widget::validator attach .c yellow {apply {text {
    expr {$text ni {{} hello world}}
}}}

widget::validator attach .n pink {apply {text {
    expr {$text ni {{} blub}}
}}}

Bugs, Ideas, Feedback

This document, and the package it describes, will undoubtedly contain bugs and other problems. Please report such in the category widget::validator of the Tklib Trackers. Please also report any ideas for enhancements you may have for either package and/or documentation.

KEYWORDS

invalid, state management, ttk::combobox, ttk::entry, validation, widget validation