<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">package WebminUI::Select;
use WebminUI::Input;
use WebminCore;
@ISA = ( "WebminUI::Input" );

=head2 new WebminUI::Select(name, value|&amp;values, &amp;options, [multiple-size],
			  [add-missing], [disabled])
Create a menu or multiple-selection field
=cut
sub new
{
if (defined(&amp;WebminUI::Theme::Select::new)) {
        return new WebminUI::Theme::Select(@_[1..$#_]);
        }
my ($self, $name, $value, $options, $size, $missing, $disabled) = @_;
$self = { 'size' =&gt; 1 };
bless($self);
$self-&gt;set_name($name);
$self-&gt;set_value($value);
$self-&gt;set_options($options);
$self-&gt;set_size($size) if (defined($size));
$self-&gt;set_missing($missing);
$self-&gt;set_disabled($disabled);
return $self;
}

=head2 add_option(name, [label])
=cut
sub add_option
{
my ($self, $name, $label) = @_;
push(@{$self-&gt;{'options'}}, [ $name, $label ]);
}

=head2 html()
Returns the HTML for this menu or multi-select input
=cut
sub html
{
my ($self) = @_;
my $dis = $self-&gt;{'form'}-&gt;get_changefunc($self);
return &amp;ui_select($self-&gt;get_name(), $self-&gt;get_value(),
			$self-&gt;get_options(), 
			$self-&gt;get_size() &gt; 1 ? $self-&gt;get_size() : undef,
			$self-&gt;get_size() &gt; 1 ? 1 : 0,
			undef,
			$self-&gt;get_disabled(),
			$dis ? "onChange='$dis'" : undef).
       ($self-&gt;get_size() &gt; 1 ? 
	       &amp;ui_hidden("ui_exists_".$self-&gt;get_name(), 1) : "");
}

=head2 get_value()
For a multi-select field, returns an array ref of all values. For a menu,
return just the one value.
=cut
sub get_value
{
my ($self) = @_;
my $in = $self-&gt;{'form'} ? $self-&gt;{'form'}-&gt;{'in'} : undef;
if ($in &amp;&amp; (defined($in-&gt;{$self-&gt;{'name'}}) ||
	    defined($in-&gt;{"ui_exists_".$self-&gt;{'name'}}))) {
	if ($self-&gt;get_size() &gt; 1) {
		return [ split(/\0/, $in-&gt;{$self-&gt;{'name'}}) ];
		}
	else {
		return $in-&gt;{$self-&gt;{'name'}};
		}
	}
elsif ($in &amp;&amp; defined($in-&gt;{"ui_value_".$self-&gt;{'name'}})) {
	if ($self-&gt;get_size() &gt; 1) {
		return [ split(/\0/, $in-&gt;{"ui_value_".$self-&gt;{'name'}}) ];
		}
	else {
		return $in-&gt;{"ui_value_".$self-&gt;{'name'}};
		}
	}
else {
	return $self-&gt;{'value'};
	}
}

sub set_options
{
my ($self, $options) = @_;
$self-&gt;{'options'} = $options;
}

sub set_size
{
my ($self, $size) = @_;
$self-&gt;{'size'} = $size;
}

sub set_missing
{
my ($self, $missing) = @_;
$self-&gt;{'missing'} = $missing;
}

sub get_options
{
my ($self) = @_;
return $self-&gt;{'options'};
}

sub get_size
{
my ($self) = @_;
return $self-&gt;{'size'};
}

sub get_missing
{
my ($self) = @_;
return $self-&gt;{'missing'};
}

=head2 validate()
Returns a list of error messages for this field
=cut
sub validate
{
my ($self) = @_;
if ($self-&gt;{'size'} &gt; 1) {
	my $value = $self-&gt;get_value();
	if ($self-&gt;{'mandatory'} &amp;&amp; !@$value) {
		return ( $self-&gt;{'mandatorymsg'} || $text{'ui_mandatory'} );
		}
	}
return ( );
}

1;

</pre></body></html>