Bugfix: NumericChoice field was misbehaving. (thanks @markwal) #2752

This commit is contained in:
Alessandro Ranellucci 2015-03-27 19:04:30 +01:00
parent 21da24e372
commit 2c13be1fa9

View File

@ -234,6 +234,9 @@ use List::Util qw(first);
use Wx qw(wxTheApp :misc :combobox); use Wx qw(wxTheApp :misc :combobox);
use Wx::Event qw(EVT_COMBOBOX EVT_TEXT); use Wx::Event qw(EVT_COMBOBOX EVT_TEXT);
# if option has no 'values', indices are values
# if option has no 'labels', values are labels
sub BUILD { sub BUILD {
my ($self) = @_; my ($self) = @_;
@ -247,15 +250,15 @@ sub BUILD {
my $disable_change_event = $self->disable_change_event; my $disable_change_event = $self->disable_change_event;
$self->disable_change_event(1); $self->disable_change_event(1);
my $value = $field->GetSelection; my $idx = $field->GetSelection; # get index of selected value
my $label; my $label;
if ($self->option->values) { if ($self->option->labels && $idx <= $#{$self->option->labels}) {
$label = $value = $self->option->values->[$value]; $label = $self->option->labels->[$idx];
} elsif ($value <= $#{$self->option->labels}) { } elsif ($self->option->values && $idx <= $#{$self->option->values}) {
$label = $self->option->labels->[$value]; $label = $self->option->values->[$idx];
} else { } else {
$label = $value; $label = $idx;
} }
# The MSW implementation of wxComboBox will leave the field blank if we call # The MSW implementation of wxComboBox will leave the field blank if we call
@ -295,8 +298,8 @@ sub set_value {
$self->disable_change_event(0); $self->disable_change_event(0);
return; return;
} }
} } elsif ($self->option->labels && $value <= $#{$self->option->labels}) {
if ($self->option->labels && $value <= $#{$self->option->labels}) { # if we have no values, we expect value to be an index
$field->SetValue($self->option->labels->[$value]); $field->SetValue($self->option->labels->[$value]);
$self->disable_change_event(0); $self->disable_change_event(0);
return; return;