<?xml version="1.0" encoding="windows-1252"?>
<node id="624410" title="Bug: Tk::Entry 804.027 validate?" created="2007-07-02 06:27:57" updated="2007-07-02 02:27:57">
<type id="115">
perlquestion</type>
<author id="123953">
strat</author>
<data>
<field name="doctext">
&lt;p&gt;Dear monks,&lt;/p&gt;

&lt;p&gt;when I use -validate with Tk::Entry, I get unexpected behaviour in combination with -textvariable and changing the variable. For this example, I used a button to change the variable $entryText which should succeed until the value of 3 and fail for bigger values.&lt;/p&gt;
&lt;code&gt;
#! /usr/bin/perl
use warnings;
use strict;
use Tk;
my $entryText = 1;
print "Perl-Version: $]\nTk-Version: $Tk::VERSION\n";

my $mw = MainWindow-&gt;new();

my $entry = $mw-&gt;Entry( -textvariable    =&gt; \$entryText,
                        -validate        =&gt; 'all',
                        -validatecommand =&gt; \&amp;ValidateCmd,
                       )
    -&gt;pack( -side =&gt; 'left' );

$mw-&gt;Button( -text    =&gt; 'increase',
             -command =&gt; sub { $entryText++ },
            )
    -&gt;pack( -side =&gt; 'right' );

MainLoop;

sub ValidateCmd {
    my( $newValue ) = @_;
    {   local $" = '] [';
        no warnings 'uninitialized'; print "ARGS: [@_]\n";
    }

    # return error if value &gt; 3 and don't change the content
    if( $newValue &gt; 3 ) {
        print "Error: Too big: $newValue\n";
        return 0;
    } # if

    return 1;
} # ValidateCmd
&lt;/code&gt;

&lt;p&gt;With Perl 5.008008 and Tk 804.024:&lt;/p&gt;
&lt;code&gt;
Perl-Version: 5.008003
Tk-Version: 800.024
ARGS: [1] [] [] [-1] [-1]
ARGS: [2] [] [1] [-1] [-1]
ARGS: [3] [] [2] [-1] [-1]
ARGS: [4] [] [3] [-1] [-1]
Error: Too big: 4
ARGS: [4] [] [3] [-1] [-1]
Error: Too big: 4
ARGS: [4] [] [3] [-1] [-1]
Error: Too big: 4
&lt;/code&gt;
&lt;p&gt;everything works fine, but with Perl-Versions &gt;= 5.008008 and Tk Version 800.027 the validation stops when the first 0 is returned and so bigger values than 3 can be inserted via $entryText:&lt;/p&gt;
&lt;code&gt;
Perl-Version: 5.008008
Tk-Version: 804.027
ARGS: [1] [] [] [-1] [6]
ARGS: [2] [] [1] [-1] [6]
ARGS: [3] [] [2] [-1] [6]
ARGS: [4] [] [3] [-1] [6]
Error: Too big: 4
&lt;/code&gt;
&lt;p&gt;and the variable may become bigger than 3 since the validation stops. Additionally, the interface of validatecommand is changed (-1 vs. 6 for the same type of action which could break a lot of existing apps).&lt;/p&gt;

&lt;p&gt;From perldoc Tk::Entry:&lt;/p&gt;
&lt;code&gt;
The validateCommand will turn itself off by setting validate to none
when an error occurs, for example when the validateCommand or
invalidCommand encounters an error in its script while evaluating, or
validateCommand does not return a valid boolean value.
&lt;/code&gt;
&lt;p&gt;But returning 0 (or undef or nothing) is no error in my eyes.&lt;/p&gt;
&lt;p&gt;Is this a bug, or am I the bug?&lt;/p&gt;

&lt;!-- Node text goes above. Div tags should contain sig only --&gt;
&lt;div class="pmsig"&gt;&lt;div class="pmsig-123953"&gt;
&lt;P&gt;
Best regards,&lt;BR&gt;
perl -e "s&gt;&gt;*F&gt;e=&gt;y)\*martinF)stronat)=&gt;print,print v8.8.8.32.11.32"
&lt;/div&gt;&lt;/div&gt;</field>
</data>
</node>
