in reply to Re^2: how to disable the button untill certain fields are filled?
in thread how to disable the button untill certain fields are filled?

In the configuration code where the table entries are being set up the fragment:

my $ent1 = $table->Entry ( -font => "verdana 10", -validate => 'key', # Pass button widget and a ref to $filled into callbac +k. Need a # ref because we manipulate $filled in the callback -vcmd => [\&onEdit, $press, \$filled], )

configures the validation call back to be called when an edit is made and to pass the additional parameters $press and \$filled (a reference to $filled) to the call back function onEdit. onEdit receives a number of parameters:

sub onEdit { my ($button, $filled, $new, $edit, $current, $idx, $type) = @_; return 1 if $new eq $current;

The first two are the two extra parameters that were passed in when the call back was set up. The remainder are the normal parameters to the validation call back. If not changes will be made to the entry contents ($new eq $current) an early exit is made. Next a check is made to see if and empty cell has had characters added, or a non-empty cell has had its contents deleted and $filled is adjusted appropriately:

if (length $new && !length $current) { ++$$filled; } elsif (!length $new && length $current) { --$$filled; }

Finally, depending on the count in $filled, the button is enabled or disabled:

if ($$filled == kRows * kCols) { $button->configure (-state => 'normal'); } else { $button->configure (-state => 'disabled'); }

Perl reduces RSI - it saves typing