Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Listbox (multiple) TV: Re-introduce rendering values by selection order #16561

Open
wants to merge 1 commit into
base: 3.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions core/lexicon/en/tv_widget.inc.php
Expand Up @@ -34,6 +34,8 @@
$_lang['combo_listwidth_desc'] = 'The width, in % or px, of the dropdown list itself. Defaults to the width of the combobox.';
$_lang['combo_maxheight'] = 'Max Height';
$_lang['combo_maxheight_desc'] = 'The maximum height in pixels of the dropdown list before scrollbars are shown. (Default: 300)';
$_lang['combo_preserve_selectionorder'] = 'Preserve Entry Order';
$_lang['combo_preserve_selectionorder_desc'] = 'When set to Yes, saved items display in the order they were originally selected. Otherwise, items follow the order defined in the list options. (Default: No)';
$_lang['combo_stackitems'] = 'Stack Selected Items';
$_lang['combo_stackitems_desc'] = 'When set to Yes, the items will be stacked 1 per line. Defaults to No, which displays the items inline.';
$_lang['combo_title'] = 'List Header';
Expand Down
Expand Up @@ -16,6 +16,7 @@
# Set values
$forceSelection = $params['forceSelection'] === 'true' || $params['forceSelection'] == 1 ? 'true' : 'false' ;
$stackItems = $params['stackItems'] === 'true' || $params['stackItems'] == 1 ? 'true' : 'false' ;
$preserveSelectionOrder = $params['preserveSelectionOrder'] === 'true' || $params['preserveSelectionOrder'] == 1 ? 'true' : 'false' ;
$typeAhead = $params['typeAhead'] === 'true' || $params['typeAhead'] == 1 ? 'true' : 'false' ;
$typeAheadDelay = !empty($params['typeAheadDelay']) ? $params['typeAheadDelay'] : 250 ;
$listHeader = !empty($params['title']) ? json_encode($params['title']) : 'null' ;
Expand All @@ -30,7 +31,8 @@
'combo_typeahead_delay_desc',
'combo_forceselection_desc',
'combo_listempty_text_desc',
'combo_stackitems_desc'
'combo_stackitems_desc',
'combo_preserve_selectionorder_desc'
];
$this->setHelpContent($descKeys, $expandHelp);

Expand Down Expand Up @@ -88,7 +90,28 @@
}]
},
{
columnWidth: 0.5,
columnWidth: 0.25,
defaults: {
anchor: '100%',
msgTarget: 'under'
},
items: [{
xtype: 'combo-boolean',
fieldLabel: _('combo_preserve_selectionorder'),
description: {$this->helpContent['eh_combo_preserve_selectionorder_desc']},
name: 'inopt_preserveSelectionOrder',
hiddenName: 'inopt_preserveSelectionOrder',
id: 'inopt_preserveSelectionOrder{$tvId}',
value: {$preserveSelectionOrder}
},{
xtype: '{$helpXtype}',
forId: 'inopt_preserveSelectionOrder{$tvId}',
html: {$this->helpContent['combo_preserve_selectionorder_desc']},
cls: 'desc-under'
}]
},
{
columnWidth: 0.25,
defaults: {
anchor: '100%',
msgTarget: 'under'
Expand Down
Expand Up @@ -77,7 +77,26 @@ public function process($value, array $params = [])
}
$items = array_merge($selections, $items);

if ($params['preserveSelectionOrder']) {
$this->reorderBySelectionOrder($savedValues, $items);
}

$this->setPlaceholder('opts', $items);
}

private function reorderBySelectionOrder(array $selections, array &$items)
{
$itemsValues = array_column($items, 'value');
$orderedSelections = [];

foreach ($selections as $selection) {
$index = array_search($selection, $itemsValues);
if ($index !== false) {
$orderedSelections[] = $items[$index];
unset($items[$index]);
}
}
$items = array_merge($orderedSelections, $items);
}
}
return 'modTemplateVarInputRenderListboxMultiple';