Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Tk::Entry validate question

by Abigail-II (Bishop)
on Jun 14, 2002 at 18:10 UTC ( [id://174666]=note: print w/replies, xml ) Need Help??


in reply to Tk::Entry validate question

That's because your validation check requires at least one number to be present. If you select all, then type, Tk will first try to delete everything - however, an empty entry is invalid, so the deletion fails.

The fix is simple. Just change the first line of your sub to:

return 0 if $_[0]=~/\D/;

Abigail

Replies are listed 'Best First'.
Re: Re: Tk::Entry validate question
by Baboon (Acolyte) on Jun 14, 2002 at 18:25 UTC
    I tried my best to explain a problem but seem not to succeed:

     1. There was an analyzis of a problem inside my message, so your explanation just rewords mine
     2. return 0 if $_[0]=~/\D/; is not enough, because I said there should be at least one digit.
     3. I noticed that I'm worried about current validation scheme in general, where validation occures one extra time, and not just once at the end of change. Number validation was just an example.

    Best wishes,
    I.R.Baboon.

      Ah, I see. Well, one thing you could do is to not validate when there's a delete (using $_ [3]). But that would enable people to erase everything (leaving nothing). I guess you could counteract that by validating on focusout as well, and using invalidCommand to put 0 or so back in the widget (or the last legal entry).

      Abigail

        In my case I really need to have that Tk::Entry to be never empty.
        The reason is following.
        I tried to use same text variable for this Tk::Entry and for other widget Tk::Scale to allow for user to either enter number by hand or to drag scale widget and enter value "visually".

        The point is - that works fine! And it seemed to me to be quite elegant solution.
        And validate works okay, but once Entry became empty (even for just a moment, when that extra validation succeedes) then strange things happen: Scale widget explains that it could not have empty value, then someone prints some Tcl_panic message, garbage could appear after some manipulation and after some other GUI manipulations it could even core dump!

        No coredumps and garbage inside Tk::Entry was noticed in my GUI app otherwise.

        So, I'm still trying to find a way to solve this!

        Best wishes,
        I.R.Baboon.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://174666]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (7)
As of 2024-04-23 19:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found