chg: [setting] Added slight support of multiselect

pull/70/head
mokaddem 2021-07-30 14:50:40 +02:00
parent aa3d7ec75e
commit a94bad8ec4
2 changed files with 14 additions and 11 deletions

View File

@ -140,6 +140,7 @@ function getResolvableID($sectionName, $panelName=false)
$('.depends-on-icon').tooltip({
placement: 'right',
})
$('select.custom-select[multiple]').select2()
$('.settings-tabs a[data-toggle="tab"]').on('shown.bs.tab', function (event) {
$('[data-spy="scroll"]').trigger('scroll.bs.scrollspy')
@ -293,4 +294,10 @@ function getResolvableID($sectionName, $panelName=false)
.form-control[type="number"] ~ div > a.btn-reset-setting {
left: -3em;
}
select.custom-select[multiple][data-setting-name] ~ span.select2-container{
min-width: unset;
}
span.select2-container--open {
min-width: unset;
}
</style>

View File

@ -72,18 +72,19 @@
]);
})($settingName, $setting, $this);
} elseif ($setting['type'] == 'select') {
} elseif ($setting['type'] == 'select' || $setting['type'] == 'multi-select') {
$input = (function ($settingName, $setting, $appView) {
$settingId = str_replace('.', '_', $settingName);
$setting['value'] = $setting['value'] ?? '';
$options = [
$appView->Bootstrap->genNode('option', ['value' => '-1', 'data-is-empty-option' => '1'], __('Select an option'))
];
$options = [];
if ($setting['type'] == 'select') {
$options[] = $appView->Bootstrap->genNode('option', ['value' => '-1', 'data-is-empty-option' => '1'], __('Select an option'));
}
foreach ($setting['options'] as $key => $value) {
$options[] = $appView->Bootstrap->genNode('option', [
'class' => [],
'value' => $key,
($setting['value'] == $value ? 'selected' : '') => $setting['value'] == $value ? 'selected' : '',
($setting['value'] == $key ? 'selected' : '') => $setting['value'] == $value ? 'selected' : '',
], h($value));
}
$options = implode('', $options);
@ -95,17 +96,12 @@
(!empty($setting['error']) ? "border-{$appView->get('variantFromSeverity')[$setting['severity']]}" : ''),
(!empty($setting['error']) ? $appView->get('variantFromSeverity')[$setting['severity']] : ''),
],
'type' => 'text',
($setting['type'] == 'multi-select' ? 'multiple' : '') => '',
'id' => $settingId,
'data-setting-name' => $settingName,
'placeholder' => $setting['default'] ?? '',
'aria-describedby' => "{$settingId}Help"
], $options);
})($settingName, $setting, $this);
} elseif ($setting['type'] == 'multi-select') {
$input = (function ($settingName, $setting, $appView) {
return '';
})($settingName, $setting, $this);
}
echo $input;