From 199bf4c044b73535d2f7cf7edd67a8025d41d03b Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Fri, 13 Apr 2018 17:10:07 +0200 Subject: [PATCH 1/2] Fix: avoid focus problem when select2 is in a modal dialog window --- htdocs/core/lib/ajax.lib.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/htdocs/core/lib/ajax.lib.php b/htdocs/core/lib/ajax.lib.php index 2ddc7125d4a..a558d97569f 100644 --- a/htdocs/core/lib/ajax.lib.php +++ b/htdocs/core/lib/ajax.lib.php @@ -386,10 +386,11 @@ function ajax_autoselect($htmlname, $addlink='') * @param int $minLengthToAutocomplete Minimum length of input string to start autocomplete * @param int $forcefocus Force focus on field * @param string $widthTypeOfAutocomplete 'resolve' or 'off' + * @param string $modalid ID of modal (for avoid focus problem when select2 is in a modal dialog window) * @return string Return html string to convert a select field into a combo, or '' if feature has been disabled for some reason. * @see selectArrayAjax of html.form.class */ -function ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete='resolve') +function ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete='resolve', $modalid='dialog-confirm') { global $conf; @@ -425,7 +426,8 @@ function ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $ }, escapeMarkup: function(markup) { return markup; - } + }, + dropdownParent: $(\'#'.$modalid.'\') })'; if ($forcefocus) $msg.= '.select2(\'focus\')'; $msg.= ';'."\n"; From 556a418132ed8d9d17973c42dd3813d7b9073818 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Fri, 13 Apr 2018 19:30:11 +0200 Subject: [PATCH 2/2] Fix: best method --- htdocs/core/lib/ajax.lib.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/htdocs/core/lib/ajax.lib.php b/htdocs/core/lib/ajax.lib.php index a558d97569f..856d7cdfbd1 100644 --- a/htdocs/core/lib/ajax.lib.php +++ b/htdocs/core/lib/ajax.lib.php @@ -386,11 +386,10 @@ function ajax_autoselect($htmlname, $addlink='') * @param int $minLengthToAutocomplete Minimum length of input string to start autocomplete * @param int $forcefocus Force focus on field * @param string $widthTypeOfAutocomplete 'resolve' or 'off' - * @param string $modalid ID of modal (for avoid focus problem when select2 is in a modal dialog window) * @return string Return html string to convert a select field into a combo, or '' if feature has been disabled for some reason. * @see selectArrayAjax of html.form.class */ -function ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete='resolve', $modalid='dialog-confirm') +function ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete='resolve') { global $conf; @@ -427,7 +426,7 @@ function ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $ escapeMarkup: function(markup) { return markup; }, - dropdownParent: $(\'#'.$modalid.'\') + dropdownCssClass: \'ui-dialog\' })'; if ($forcefocus) $msg.= '.select2(\'focus\')'; $msg.= ';'."\n";