From 017e384f16c0f25c65163c4bb991b450abe11a80 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 6 Dec 2016 13:10:44 +0100 Subject: [PATCH] FIX Preselected value for extrafield link was not correctly set --- htdocs/core/class/commonobject.class.php | 4 ++-- htdocs/core/class/extrafields.class.php | 19 +++++++++++++------ 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index de42ced0997..e9a7607d011 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -4470,10 +4470,10 @@ abstract class CommonObject switch($mode) { case "view": - $out .= $extrafields->showOutputField($key,$value); + $out .= $extrafields->showOutputField($key, $value); break; case "edit": - $out .= $extrafields->showInputField($key,$value,'',$keyprefix,'',0,$this->id); + $out .= $extrafields->showInputField($key, $value, '', $keyprefix, '', 0, $this->id); break; } diff --git a/htdocs/core/class/extrafields.class.php b/htdocs/core/class/extrafields.class.php index ca7f0c24958..b18738bde9f 100644 --- a/htdocs/core/class/extrafields.class.php +++ b/htdocs/core/class/extrafields.class.php @@ -660,7 +660,7 @@ class ExtraFields * Return HTML string to put an input field into a page * * @param string $key Key of attribute - * @param string $value Value to show (for date type it must be in timestamp format) + * @param string $value Preselected value to show (for date type it must be in timestamp format) * @param string $moreparam To add more parametes on html input tag * @param string $keyprefix Prefix string to add into name and id of field (can be used to avoid duplicate names) * @param string $keysuffix Suffix string to add into name and id of field (can be used to avoid duplicate names) @@ -668,7 +668,7 @@ class ExtraFields * @param int $objectid Current object id * @return string */ - function showInputField($key,$value,$moreparam='',$keyprefix='',$keysuffix='',$showsize=0, $objectid=0) + function showInputField($key, $value, $moreparam='', $keyprefix='', $keysuffix='', $showsize=0, $objectid=0) { global $conf,$langs; @@ -1163,10 +1163,17 @@ class ExtraFields dol_include_once($InfoFieldList[1]); if ($InfoFieldList[0] && class_exists($InfoFieldList[0])) { - $object = new $InfoFieldList[0]($this->db); - if (!empty($value)) $object->fetch($value); - $valuetoshow=$object->ref; - if ($object->element == 'societe') $valuetoshow=$object->name; // Special case for thirdparty because ref is id because name is not unique + $valuetoshow=$value; + if (!empty($value)) + { + $object = new $InfoFieldList[0]($this->db); + $resfetch=$object->fetch($value); + if ($resfetch > 0) + { + $valuetoshow=$object->ref; + if ($object->element == 'societe') $valuetoshow=$object->name; // Special case for thirdparty because ->ref is not name but id (because name is not unique) + } + } $out.=''; } else