Re: why I can't input chars in the entryfield ?
- From: Bruce <news@xxxxxxxxxxx>
- Date: Sat, 25 Nov 2006 18:50:13 -0600
Harry wrote:
iwidgets::entryfield .getDate.efCode -labeltext "Stock Code:" -validate
{check_code %W "%c"}
proc check_code {entry char} {
set current [$entry get]
set len [string length $current]
if {$len == 8} {
$entry delete 0 end
$entry insert 0 "$current"
}
if {$len == 8 && [regexp {s[z|h][\d]{6}?} $current]} {
return 1
}
return 0
}
Here my proc check_code is to insure the input is like "sz000063",
Do you guys have any better solutions?
OK,
You're doing a few things wrong here ;)
One is you are never looking at the new character - all your
checking is based on the current widget state (i.e. you aren't
looking at what adding the new char does. you're also doing a bunch of
unneccessary stuff where you delete and readd the exact same contents
now point in that. And finally your check is only looking for something
that matches the final state all 8 chars that match your RE so first of
all you are always dealing with an empty field, ignoring input and for
a final answer so you will always fail. If you looked at the new stuff
coming in it would only work if you pasted it in all at once. So, that
being said I would propose the following:
use the %P substitution char which gives you a lookahead at what will
be in your entry if you allow the edit and make sure your RE will
match partial answers so the user can enter things
iwidgets::entryfield .getDate.efCode -labeltext "Stock Code:" \
-validate {check_code %P}
proc check_code {str} {
return [regexp {s([h|z]\d{0-6})?}} $str]
}
that RE should match a single s, an s followed by z or h, or
one of those char combos followed by zero to six chars.
Bruce
.
- References:
- why I can't input chars in the entryfield ?
- From: Harry
- why I can't input chars in the entryfield ?
- Prev by Date: Re: TCL/PHP/XML problem: I need to convert an XML file into a TCL list
- Next by Date: Re: Using Webservices with Tcl
- Previous by thread: why I can't input chars in the entryfield ?
- Next by thread: Problem installing cgi.tcl on winXP
- Index(es):
Relevant Pages
|