Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

Dear monks,

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.

#! /usr/bin/perl use warnings; use strict; use Tk; my $entryText = 1; print "Perl-Version: $]\nTk-Version: $Tk::VERSION\n"; my $mw = MainWindow->new(); my $entry = $mw->Entry( -textvariable => \$entryText, -validate => 'all', -validatecommand => \&ValidateCmd, ) ->pack( -side => 'left' ); $mw->Button( -text => 'increase', -command => sub { $entryText++ }, ) ->pack( -side => 'right' ); MainLoop; sub ValidateCmd { my( $newValue ) = @_; { local $" = '] ['; no warnings 'uninitialized'; print "ARGS: [@_]\n"; } # return error if value > 3 and don't change the content if( $newValue > 3 ) { print "Error: Too big: $newValue\n"; return 0; } # if return 1; } # ValidateCmd

With Perl 5.008008 and Tk 804.024:

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

everything works fine, but with Perl-Versions >= 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:

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

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).

From perldoc Tk::Entry:

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.

But returning 0 (or undef or nothing) is no error in my eyes.

Is this a bug, or am I the bug?

Best regards,
perl -e "s>>*F>e=>y)\*martinF)stronat)=>print,print v8.8.8.32.11.32"


In reply to Bug: Tk::Entry 804.027 validate? by strat

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others lurking in the Monastery: (7)
    As of 2014-12-20 05:14 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      Is guessing a good strategy for surviving in the IT business?





      Results (95 votes), past polls