Enhance select2 component to allow onrightofpage

This commit is contained in:
Laurent Destailleur 2023-01-05 03:12:52 +01:00
parent 0e276fba5e
commit 761ca8ca43
3 changed files with 15 additions and 7 deletions

View File

@ -480,8 +480,11 @@ function ajax_combobox($htmlname, $events = array(), $minLengthToAutocomplete =
<script> <script>
$(document).ready(function () { $(document).ready(function () {
$(\''.(preg_match('/^\./', $htmlname) ? $htmlname : '#'.$htmlname).'\').'.$tmpplugin.'({ $(\''.(preg_match('/^\./', $htmlname) ? $htmlname : '#'.$htmlname).'\').'.$tmpplugin.'({
dir: \'ltr\', dir: \'ltr\',';
width: \''.dol_escape_js($widthTypeOfAutocomplete).'\', /* off or resolve */ if (preg_match('/onrightofpage/', $morecss)) { // when $morecss contains 'onrightofpage', the select2 component must also be inside a parent with class="parentonrightofpage"
$msg .= ' dropdownAutoWidth: true, dropdownParent: $(\'#'.$htmlname.'\').parent(), '."\n";
}
$msg .= ' width: \''.dol_escape_js($widthTypeOfAutocomplete).'\', /* off or resolve */
minimumInputLength: '.((int) $minLengthToAutocomplete).', minimumInputLength: '.((int) $minLengthToAutocomplete).',
language: select2arrayoflanguage, language: select2arrayoflanguage,
matcher: function (params, data) { matcher: function (params, data) {
@ -499,6 +502,7 @@ function ajax_combobox($htmlname, $events = array(), $minLengthToAutocomplete =
theme: \'default'.$moreselect2theme.'\', /* to add css on generated html components */ theme: \'default'.$moreselect2theme.'\', /* to add css on generated html components */
containerCssClass: \':all:\', /* Line to add class of origin SELECT propagated to the new <span class="select2-selection...> tag */ containerCssClass: \':all:\', /* Line to add class of origin SELECT propagated to the new <span class="select2-selection...> tag */
selectionCssClass: \':all:\', /* Line to add class of origin SELECT propagated to the new <span class="select2-selection...> tag */ selectionCssClass: \':all:\', /* Line to add class of origin SELECT propagated to the new <span class="select2-selection...> tag */
dropdownCssClass: \'ui-dialog\',
templateResult: function (data, container) { /* Format visible output into combo list */ templateResult: function (data, container) { /* Format visible output into combo list */
/* Code to add class of origin OPTION propagated to the new select2 <li> tag */ /* Code to add class of origin OPTION propagated to the new select2 <li> tag */
if (data.element) { $(container).addClass($(data.element).attr("class")); } if (data.element) { $(container).addClass($(data.element).attr("class")); }
@ -515,8 +519,7 @@ function ajax_combobox($htmlname, $events = array(), $minLengthToAutocomplete =
}, },
escapeMarkup: function(markup) { escapeMarkup: function(markup) {
return markup; return markup;
}, }
dropdownCssClass: \'ui-dialog\'
})'; })';
if ($forcefocus) { if ($forcefocus) {
$msg .= '.select2(\'focus\')'; $msg .= '.select2(\'focus\')';

View File

@ -1142,12 +1142,12 @@ if (!empty($arrayfields['p.tms']['checked'])) {
print '</td>'; print '</td>';
} }
if (!empty($arrayfields['p.tosell']['checked'])) { if (!empty($arrayfields['p.tosell']['checked'])) {
print '<td class="liste_titre center">'; print '<td class="liste_titre center parentonrightofpage">';
print $form->selectarray('search_tosell', array('0'=>$langs->trans('ProductStatusNotOnSellShort'), '1'=>$langs->trans('ProductStatusOnSellShort')), $search_tosell, 1, 0, 0, '', 0, 0, 0, '', 'search_status width100 onrightofpage'); print $form->selectarray('search_tosell', array('0'=>$langs->trans('ProductStatusNotOnSellShort'), '1'=>$langs->trans('ProductStatusOnSellShort')), $search_tosell, 1, 0, 0, '', 0, 0, 0, '', 'search_status width100 onrightofpage');
print '</td>'; print '</td>';
} }
if (!empty($arrayfields['p.tobuy']['checked'])) { if (!empty($arrayfields['p.tobuy']['checked'])) {
print '<td class="liste_titre center">'; print '<td class="liste_titre center parentonrightofpage">';
print $form->selectarray('search_tobuy', array('0'=>$langs->trans('ProductStatusNotOnBuyShort'), '1'=>$langs->trans('ProductStatusOnBuyShort')), $search_tobuy, 1, 0, 0, '', 0, 0, 0, '', 'search_status width100 onrightofpage'); print $form->selectarray('search_tobuy', array('0'=>$langs->trans('ProductStatusNotOnBuyShort'), '1'=>$langs->trans('ProductStatusOnBuyShort')), $search_tobuy, 1, 0, 0, '', 0, 0, 0, '', 'search_status width100 onrightofpage');
print '</td>'; print '</td>';
} }

View File

@ -1715,6 +1715,11 @@ select.widthcentpercentminusxx, span.widthcentpercentminusxx:not(.select2-select
display: inline-block; display: inline-block;
} }
.parentonrightofpage {
direction: rtl;
}
/* Force values for small screen 767 */ /* Force values for small screen 767 */
@media only screen and (max-width: 767px) @media only screen and (max-width: 767px)
{ {