Skip to content

Commit fe2130b

Browse files
committed
fix(glpiselectfield): cannot set empty value by default for entity question
1 parent 4b70dff commit fe2130b

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

inc/field/dropdownfield.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ public function buildParams($rand = null) {
340340
if ($itemtype != Entity::class) {
341341
$dparams['display_emptychoice'] = ($this->question->fields['show_empty'] !== '0');
342342
} else {
343-
if ($this->question->fields['show_empty'] !== '0') {
343+
if ($this->question->fields['show_empty'] != '0') {
344344
$dparams['toadd'] = [
345345
-1 => Dropdown::EMPTY_VALUE,
346346
];

templates/field/glpiselectfield.html.twig

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,21 @@
6262
) }}
6363

6464
{% if item.fields['itemtype'] is defined and item.fields['itemtype'] != '0' %}
65+
{% set to_add = {} %}
66+
{% if item.fields['itemtype'] == 'Entity' %}
67+
{% set default_values = item.fields['default_values'] == '' ? -1 : item.fields['default_values'] %}
68+
{% set to_add = {
69+
'-1': constant('Dropdown::EMPTY_VALUE'),
70+
} %}
71+
{% endif %}
6572
{{ fields.dropdownField(
6673
item.fields['itemtype'],
6774
'default_values',
68-
item.fields['default_values'],
75+
default_values,
6976
__('Default values'), {
7077
label_class: 'col-xxl-4',
7178
input_class: 'col-xxl-8',
79+
toadd: to_add,
7280
}
7381
) }}
7482
{% else %}

0 commit comments

Comments
 (0)