Handle hostnames with upper-case letters
[webmin.git] / Webmin / OptTextbox.pm
1 package Webmin::OptTextbox;
2 use Webmin::Textbox;
3 use WebminCore;
4 @ISA = ( "Webmin::Textbox" );
5
6 =head2 new Webmin::OptTextbox(name, value, size, [default-msg], [other-msg])
7 Create a text field whose value is optional.
8 =cut
9 sub new
10 {
11 if (defined(&Webmin::Theme::OptTextbox::new)) {
12         return new Webmin::Theme::OptTextbox(@_[1..$#_]);
13         }
14 my ($self, $name, $value, $size, $default, $other) = @_;
15 $self = new Webmin::Textbox($name, $value, $size);
16 bless($self);
17 $self->set_default($default || $text{'default'});
18 $self->set_other($other) if ($other);
19 return $self;
20 }
21
22 =head2 html()
23 Returns the HTML for this optional text input
24 =cut
25 sub html
26 {
27 my ($self) = @_;
28 return &ui_opt_textbox($self->get_name(), $self->get_value(),
29                              $self->{'size'}, $self->{'default'},
30                              $self->{'other'});
31 }
32
33 =head2 validate(&inputs)
34 =cut
35 sub validate
36 {
37 my ($self, $in) = @_;
38 if (defined($self->get_value())) {
39         if ($self->get_value() eq "") {
40                 return ( $text{'ui_nothing'} );
41                 }
42         return Webmin::Textbox::validate($self);
43         }
44 return ( );
45 }
46
47 sub set_default
48 {
49 my ($self, $default) = @_;
50 $self->{'default'} = $default;
51 }
52
53 sub set_other
54 {
55 my ($self, $other) = @_;
56 $self->{'other'} = $other;
57 }
58
59 =head2 get_value()
60 Returns the specified initial value for this field, or the value set when the
61 form is re-displayed due to an error.
62 =cut
63 sub get_value
64 {
65 my ($self) = @_;
66 my $in = $self->{'form'} ? $self->{'form'}->{'in'} : undef;
67 if ($in && (defined($in->{$self->{'name'}}) ||
68             defined($in->{$self->{'name'}.'_def'}))) {
69         return $in->{$self->{'name'}.'_def'} ? undef : $in->{$self->{'name'}};
70         }
71 elsif ($in && defined($in->{"ui_value_".$self->{'name'}})) {
72         return $in->{"ui_value_".$self->{'name'}};
73         }
74 else {
75         return $self->{'value'};
76         }
77 }
78
79 =head2 get_input_names()
80 Returns the actual names of all HTML elements that make up this input
81 =cut
82 sub get_input_names
83 {
84 my ($self) = @_;
85 return ( $self->{'name'}, $self->{'name'}."_def[0]",
86                           $self->{'name'}."_def[1]" );
87 }
88
89 1;
90