Skip to content

Commit

Permalink
fix(dropdownfields): handle empty value for entities dropdown
Browse files Browse the repository at this point in the history
Signed-off-by: Thierry Bugier <[email protected]>
  • Loading branch information
btry committed Feb 24, 2020
1 parent 2d726c9 commit 47b47ef
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
16 changes: 12 additions & 4 deletions ajax/dropdown_values.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
11 changes: 10 additions & 1 deletion inc/fields/dropdownfield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 47b47ef

Please sign in to comment.