Fix combo when we must no hide value with key -1

This commit is contained in:
Laurent Destailleur 2021-05-25 22:51:37 +02:00
parent 8f9de222c1
commit 8576cf1b72
3 changed files with 8 additions and 7 deletions

View File

@ -708,7 +708,7 @@ if (!empty($arrayfields['d.morphy']['checked'])) {
if (!empty($arrayfields['t.libelle']['checked'])) { if (!empty($arrayfields['t.libelle']['checked'])) {
print '<td class="liste_titre">'; print '<td class="liste_titre">';
$listetype = $membertypestatic->liste_array(); $listetype = $membertypestatic->liste_array();
print $form->selectarray("search_type", $listetype, $type, 1, 0, 0, '', 0, 32); print $form->selectarray("search_type", $listetype, $search_type, 1, 0, 0, '', 0, 32);
print '</td>'; print '</td>';
} }
@ -792,8 +792,8 @@ if (!empty($arrayfields['d.statut']['checked'])) {
$liststatus = array( $liststatus = array(
'-1'=>$langs->trans("Draft"), '-1'=>$langs->trans("Draft"),
'1'=>$langs->trans("Validated"), '1'=>$langs->trans("Validated"),
'0'=>$langs->trans("Resiliated"), '0'=>$langs->trans("MemberStatusResiliatedShort"),
'-2'=>$langs->trans("Excluded") '-2'=>$langs->trans("MemberStatusExcludedShort")
); );
print $form->selectarray('search_status', $liststatus, $search_status, -3); print $form->selectarray('search_status', $liststatus, $search_status, -3);
print '</td>'; print '</td>';

View File

@ -6924,7 +6924,7 @@ class Form
if ($addjscombo && $jsbeautify) { if ($addjscombo && $jsbeautify) {
// Enhance with select2 // Enhance with select2
include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php'; include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
$out .= ajax_combobox($htmlname); $out .= ajax_combobox($htmlname, array(), 0, 0, 'resolve', $show_empty < 0 ? (string) $show_empty : '-1');
} }
$out .= '<select id="'.preg_replace('/^\./', '', $htmlname).'" '.($disabled ? 'disabled="disabled" ' : '').'class="flat '.(preg_replace('/^\./', '', $htmlname)).($morecss ? ' '.$morecss : '').'"'; $out .= '<select id="'.preg_replace('/^\./', '', $htmlname).'" '.($disabled ? 'disabled="disabled" ' : '').'class="flat '.(preg_replace('/^\./', '', $htmlname)).($morecss ? ' '.$morecss : '').'"';

View File

@ -411,10 +411,11 @@ function ajax_dialog($title, $message, $w = 350, $h = 150)
* @param int $minLengthToAutocomplete Minimum length of input string to start autocomplete * @param int $minLengthToAutocomplete Minimum length of input string to start autocomplete
* @param int $forcefocus Force focus on field * @param int $forcefocus Force focus on field
* @param string $widthTypeOfAutocomplete 'resolve' or 'off' * @param string $widthTypeOfAutocomplete 'resolve' or 'off'
* @param string $idforemptyvalue '-1'
* @return string Return html string to convert a select field into a combo, or '' if feature has been disabled for some reason. * @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 * @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', $idforemptyvalue = '-1')
{ {
global $conf; global $conf;
@ -455,14 +456,14 @@ function ajax_combobox($htmlname, $events = array(), $minLengthToAutocomplete =
/* 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")); }
//console.log($(data.element).attr("data-html")); //console.log($(data.element).attr("data-html"));
if (data.id == -1 && $(data.element).attr("data-html") == undefined) { if (data.id == '.((int) $idforemptyvalue).' && $(data.element).attr("data-html") == undefined) {
return \'&nbsp;\'; return \'&nbsp;\';
} }
if ($(data.element).attr("data-html") != undefined) return htmlEntityDecodeJs($(data.element).attr("data-html")); // If property html set, we decode html entities and use this if ($(data.element).attr("data-html") != undefined) return htmlEntityDecodeJs($(data.element).attr("data-html")); // If property html set, we decode html entities and use this
return data.text; return data.text;
}, },
templateSelection: function (selection) { /* Format visible output of selected value */ templateSelection: function (selection) { /* Format visible output of selected value */
if (selection.id == -1) return \'<span class="placeholder">\'+selection.text+\'</span>\'; if (selection.id == '.((int) $idforemptyvalue).') return \'<span class="placeholder">\'+selection.text+\'</span>\';
return selection.text; return selection.text;
}, },
escapeMarkup: function(markup) { escapeMarkup: function(markup) {