From fe2130bbecf423d74ea148f05df88e138c2a9f31 Mon Sep 17 00:00:00 2001 From: Thierry Bugier Date: Fri, 9 Dec 2022 14:25:15 +0100 Subject: [PATCH] fix(glpiselectfield): cannot set empty value by default for entity question --- inc/field/dropdownfield.class.php | 2 +- templates/field/glpiselectfield.html.twig | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/inc/field/dropdownfield.class.php b/inc/field/dropdownfield.class.php index bf6031045..d8be15fa4 100644 --- a/inc/field/dropdownfield.class.php +++ b/inc/field/dropdownfield.class.php @@ -340,7 +340,7 @@ public function buildParams($rand = null) { if ($itemtype != Entity::class) { $dparams['display_emptychoice'] = ($this->question->fields['show_empty'] !== '0'); } else { - if ($this->question->fields['show_empty'] !== '0') { + if ($this->question->fields['show_empty'] != '0') { $dparams['toadd'] = [ -1 => Dropdown::EMPTY_VALUE, ]; diff --git a/templates/field/glpiselectfield.html.twig b/templates/field/glpiselectfield.html.twig index 363e14de4..cf95ae79b 100644 --- a/templates/field/glpiselectfield.html.twig +++ b/templates/field/glpiselectfield.html.twig @@ -62,13 +62,21 @@ ) }} {% if item.fields['itemtype'] is defined and item.fields['itemtype'] != '0' %} + {% set to_add = {} %} + {% if item.fields['itemtype'] == 'Entity' %} + {% set default_values = item.fields['default_values'] == '' ? -1 : item.fields['default_values'] %} + {% set to_add = { + '-1': constant('Dropdown::EMPTY_VALUE'), + } %} + {% endif %} {{ fields.dropdownField( item.fields['itemtype'], 'default_values', - item.fields['default_values'], + default_values, __('Default values'), { label_class: 'col-xxl-4', input_class: 'col-xxl-8', + toadd: to_add, } ) }} {% else %}