Francois Perrad

NAME

Tk::FilterEntry - An entry with filter

SYNOPSIS

        use Tk::FilterEntry;

        $entry = $parent->FilterEntry(?options?);
        $entry->pack;

DESCRIPTION

This widget is derived from Tk::Entry and it implements an other way of validation. The input is validate by a callback or more simply by a filter, when the entry leaves the focus. And if is invalid, the foreground color is changed.

So, this widget deals well with textVariable.

OPTIONS

-fg_valid (new option)

The color of the input text when it is valid.

The default value is 'black'.

-fg_invalid (new option)

The color of the input text when it is not valid.

The default value is 'red'.

-filter (new option)

This filter specifies the valid range of the input.

The filter is used if validatecommand is not defined.

The filter is a Perl regular expression.

The default value is '.*' (every is valid).

-trim (new option)

If the boolean value specified is true, the leading and trailing whitespace are skipped before apply the filter.

The default value is 1.

-anchors (new option)

If the boolean value specified is true, the two anchors '^' and '$' are added to the filter.

The default value is 1.

-validatecommand (overloaded option)

This Entry callback is called if defined. The boolean value returned defines if the input is valid.

The validateCommand and invalidCommand are called with first argument: the reference of the entry (It is a major different with Tk::Entry) and following by parameters of the closure.

The default value is <undef>.

-invalidcommand (overloaded option)

This Entry callback is called if the return of validateCommand is false or if the input doesn't match with the pattern.

The default value is <undef>.

METHODS

$entry->validate() (overloaded method)

This command is used to force an evaluation of the validateCommand or of the filter.

It returns boolean.

EXAMPLE

    my $hour;           # with format HH:mm
    my $e_hour = $mw->FilterEntry(
        -filter          => '[0-2]?\d:[0-5]?\d',
        -invalidcommand  => sub { print "invalid ",shift->get(),"\n" },
        -textvariable    => \$hour,
        -width           => 15,
    );

or

    my $hour;           # with format HH:mm
    my $e_hour = $mw->FilterEntry(
        -validatecommand => sub { shift->get() =~ /^\s*[0-2]?\d:[0-5]?\d\s*$/ },
        -invalidcommand  => sub { print "invalid ",shift->get(),"\n" },
        -textvariable    => \$hour,
        -width           => 15,
    );

or

    my $hour;           # with format HH:mm
    my $e_hour = $mw->FilterEntry(
        -validatecommand => [ sub { $_[0]->get() =~ /$_[1]/ },
                              '^\s*[0-2]?\d:[0-5]?\d\s*$' ],
        -invalidcommand  => sub { print "invalid ",shift->get(),"\n" },
        -textvariable    => \$hour,
        -width           => 15,
    );

SEE ALSO

Tk::Entry

COPYRIGHT

(c) 2003 Francois PERRAD, France. All rights reserved.

This library is distributed under the terms of the Artistic Licence.

AUTHOR

Francois PERRAD, francois.perrad@gadz.org




Hosting generously
sponsored by Bytemark