mirror of
https://github.com/webmin/webmin.git
synced 2026-09-16 02:20:39 +01:00
Fix positional multi-select list compatibility
ⓘ Preserve selected labels, value order and pre-escaped text when callers omit the options hash.
This commit is contained in:
@@ -509,6 +509,17 @@ like(main::ui_form_columns_table('x.cgi', [ [ 'go', 'Go' ] ], 0, undef, undef,
|
||||
is_deeply(\@disabled, [ 1, 0 ], 'themes receive the normalized disabled state');
|
||||
}
|
||||
|
||||
# Three-argument callers retain legacy selected labels and order.
|
||||
{
|
||||
my $values = [ [ 'b', 'Selected & saved' ], [ 'a', 'A' ] ];
|
||||
my $options = [ [ 'a', 'R&D' ], [ 'b', 'Available' ] ];
|
||||
my $html = main::ui_multi_select_list('short', $values, $options);
|
||||
like($html, qr/name="short"[^>]*value="b\na"/,
|
||||
'omitting size preserves the supplied selection order');
|
||||
like($html, qr/>Selected & saved</,
|
||||
'omitting size preserves the selected description and escaped text');
|
||||
}
|
||||
|
||||
# Positional calls preserve the old selected pane's labels and value order.
|
||||
{
|
||||
my @values = ( [ 'b', 'B (selected)', q{disabled title="Selected"} ],
|
||||
@@ -561,7 +572,7 @@ like(main::ui_form_columns_table('x.cgi', [ [ 'go', 'Go' ] ], 0, undef, undef,
|
||||
my ($filter) = $html =~ /data-ui-multi-text="([^"]*)"/;
|
||||
is($filter, $label, 'filter label retains original UTF-8 bytes and case');
|
||||
my $literal = 'R&D';
|
||||
$html = main::ui_multi_select_list('g', [ ], [ [ 'team', $literal ] ]);
|
||||
$html = main::ui_multi_select_list('g', [ ], [ [ 'team', $literal ] ], {});
|
||||
($filter) = $html =~ /data-ui-multi-text="([^"]*)"/;
|
||||
is(decode_attr($filter), $literal,
|
||||
'filter text preserves literal HTML entity names in plain labels');
|
||||
|
||||
11
ui-lib.pl
11
ui-lib.pl
@@ -5727,10 +5727,11 @@ Shift-click applies the clicked state from the last clicked entry to the
|
||||
current one, skipping filtered, folded and disabled entries. Labels and row
|
||||
backgrounds work too.
|
||||
|
||||
Accepts an options hash or ui_multi_select's trailing positional arguments.
|
||||
Positional calls preserve selected labels, attributes, value order and
|
||||
pre-escaped label text. Newly selected entries are prepended as in the old
|
||||
widget. Size, add-if-missing, titles and width are ignored.
|
||||
Accepts an options hash or the legacy trailing positional arguments.
|
||||
Calls without an options hash preserve selected labels, attributes, value
|
||||
order and pre-escaped label text. Newly selected entries are prepended as in the old
|
||||
widget. Pass an options hash (even empty) for plain labels and option ordering.
|
||||
Size, add-if-missing, titles and width are ignored.
|
||||
|
||||
=item name - HTML name for the input.
|
||||
|
||||
@@ -5764,7 +5765,7 @@ sub ui_multi_select_list
|
||||
return &theme_ui_multi_select_list(@_)
|
||||
if (defined(&theme_ui_multi_select_list));
|
||||
my ($name, $values, $options, $opts) = @_;
|
||||
my $legacy = @_ > 3 && ref($opts) ne 'HASH';
|
||||
my $legacy = ref($opts) ne 'HASH';
|
||||
if (ref($opts) ne 'HASH') {
|
||||
# Accept ui_multi_select's positional disabled argument.
|
||||
$opts = { 'disabled' => $_[5] };
|
||||
|
||||
Reference in New Issue
Block a user