From b81e03bfa7fbe166c0225f303b7e49522cca5a32 Mon Sep 17 00:00:00 2001 From: aydreeihn <adriane@enhancesoft.com> Date: Fri, 23 Mar 2018 13:10:20 -0500 Subject: [PATCH] correctly filter departmentfield. use departmentfield for referrals --- include/class.forms.php | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/include/class.forms.php b/include/class.forms.php index 161e06fdb..cc6572a3e 100644 --- a/include/class.forms.php +++ b/include/class.forms.php @@ -2690,15 +2690,12 @@ class DepartmentField extends ChoiceField { else { $current_id = $selected->value; $current_name = Dept::getNameById($current_id); - $addNew = true; } } - $active_depts = array(); - if($current_id) - $active_depts = Dept::objects() - ->filter(array('flags__hasbit' => Dept::FLAG_ACTIVE)) - ->values('id', 'name'); + $active_depts = Dept::objects() + ->filter(array('flags__hasbit' => Dept::FLAG_ACTIVE)) + ->values('id', 'name'); $choices = array(); if ($depts = Dept::getDepartments(null, true, Dept::DISPLAY_DISABLED)) { @@ -2708,18 +2705,17 @@ class DepartmentField extends ChoiceField { $active[$dept['id']] = $dept['name']; //add selected dept to list - $active[$current_id] = $current_name; - + if($current_id) + $active[$current_id] = $current_name; + else + return $active; foreach ($depts as $id => $name) { $choices[$id] = $name; if(!array_key_exists($id, $active) && $current_id) - unset($choices[$id]); + unset($choices[$id]); } - } - if($addNew) - $choices[':new:'] = '— '.__('Add New').' —'; return $choices; } @@ -3933,6 +3929,8 @@ class ChoicesWidget extends Widget { $values[$v] = $choices[$v]; elseif (($i=$this->field->lookupChoice($v))) $values += $i; + elseif (!$k && $v) + return $v; } } } @@ -4916,7 +4914,7 @@ class ReferralForm extends Form { ), ) ), - 'dept' => new ChoiceField(array( + 'dept' => new DepartmentField(array( 'id'=>4, 'label' => '', 'flags' => hexdec(0X450F3), -- GitLab