Skip to content

Commit

Permalink
fix(glpiselectfield): cannot set empty value by default for entity qu…
Browse files Browse the repository at this point in the history
…estion
  • Loading branch information
btry committed Dec 12, 2022
1 parent 4b70dff commit fe2130b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion inc/field/dropdownfield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
];
Expand Down
10 changes: 9 additions & 1 deletion templates/field/glpiselectfield.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
Expand Down

0 comments on commit fe2130b

Please sign in to comment.