diff --git a/ajax/dropdown_values.php b/ajax/dropdown_values.php index 275f6013c..1d459972e 100644 --- a/ajax/dropdown_values.php +++ b/ajax/dropdown_values.php @@ -37,20 +37,28 @@ || $_REQUEST['dropdown_itemtype'] == '0' || !class_exists($_REQUEST['dropdown_itemtype'])) { Dropdown::showFromArray( - 'dropdown_default_value', + 'dropdown_default_value', [], [ 'display_emptychoice' => true ] ); } else { + $itemtype = $_REQUEST['dropdown_itemtype']; $question = new PluginFormcreatorQuestion(); $question->getFromDB((int) $_REQUEST['id']); - $defaultValue = isset($question->fields['default_values']) + $defaultValue = isset($question->fields['default_values']) ? $question->fields['default_values'] : 0; - Dropdown::show($_REQUEST['dropdown_itemtype'], [ + + $options = [ 'name' => 'dropdown_default_value', 'rand' => mt_rand(), 'value' => $defaultValue, - ]); + ]; + if ($itemtype == Entity::class) { + $options['toadd'] = [ + -1 => Dropdown::EMPTY_VALUE, + ]; + } + Dropdown::show($itemtype, $options); } diff --git a/inc/fields/dropdownfield.class.php b/inc/fields/dropdownfield.class.php index 01671a2c4..e3e1f55d1 100644 --- a/inc/fields/dropdownfield.class.php +++ b/inc/fields/dropdownfield.class.php @@ -253,7 +253,16 @@ public function displayField($canEdit = true) { $dparams['condition'] = $dparams_cond_crit; - $dparams['display_emptychoice'] = ($this->question->fields['show_empty'] !== '0'); + $dparams['display_emptychoice'] = false; + if ($itemtype != Entity::class) { + $dparams['display_emptychoice'] = ($this->question->fields['show_empty'] !== '0'); + } else { + if ($this->question->fields['show_empty'] !== '0') { + $dparams['toadd'] = [ + -1 => Dropdown::EMPTY_VALUE, + ]; + } + } $emptyItem = new $itemtype(); $emptyItem->getEmpty();