diff --git a/htdocs/core/actions_addupdatedelete.inc.php b/htdocs/core/actions_addupdatedelete.inc.php
index c7e57641c29..b2ec79af5a7 100644
--- a/htdocs/core/actions_addupdatedelete.inc.php
+++ b/htdocs/core/actions_addupdatedelete.inc.php
@@ -87,6 +87,7 @@ if ($action == 'update' && ! empty($permissiontoadd))
{
foreach ($object->fields as $key => $val)
{
+ if (! GETPOSTISSET($key)) continue; // The field was not submited to be edited
if (in_array($key, array('rowid', 'entity', 'date_creation', 'tms', 'fk_user_creat', 'fk_user_modif', 'import_key'))) continue; // Ignore special fields
$value = GETPOST($key,'alpha');
diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php
index fcf6c913e27..47b27641436 100644
--- a/htdocs/core/class/commonobject.class.php
+++ b/htdocs/core/class/commonobject.class.php
@@ -1396,7 +1396,7 @@ abstract class CommonObject
}
/**
- * Load properties id_previous and id_next
+ * Load properties id_previous and id_next by comparing $fieldid with $this->ref
*
* @param string $filter Optional filter. Example: " AND (t.field1 = 'aa' OR t.field2 = 'bb')"
* @param string $fieldid Name of field to use for the select MAX and MIN
@@ -1433,7 +1433,7 @@ abstract class CommonObject
if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 2) $sql.= ' AND te.fk_soc = s.rowid'; // If we need to link to societe to limit select to entity
if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) $sql.= ' AND te.entity IN ('.getEntity($this->element, 1).')';
- //print $filter.' '.$sql."
";
+ //print 'filter = '.$filter.' -> '.$sql."
";
$result = $this->db->query($sql);
if (! $result)
{
@@ -6044,7 +6044,7 @@ abstract class CommonObject
}
/**
- * Function to load data into current object this
+ * Function to load data from a SQL pointer into properties of current object $this
*
* @param stdClass $obj Contain data of object from database
*/
@@ -6082,8 +6082,10 @@ abstract class CommonObject
{
$this->{$field} = $obj->{$field};
}
-
}
+
+ // If there is no 'ref' field, we force property ->ref to ->id for a better compatibility with common functions.
+ if (! isset($this->fields['ref']) && isset($this->id)) $this->ref = $this->id;
}
/**
diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php
index 33a591b0fb3..7df1fd1f4a2 100644
--- a/htdocs/core/class/html.form.class.php
+++ b/htdocs/core/class/html.form.class.php
@@ -6158,13 +6158,13 @@ class Form
/**
* Return a HTML area with the reference of object and a navigation bar for a business object
- * Note: To add a particular filter on select, you can have $object->next_prev_filter set to add SQL criterias.
+ * Note: To complete search with a particular filter on select, you can set $object->next_prev_filter set to define SQL criterias.
*
* @param object $object Object to show.
* @param string $paramid Name of parameter to use to name the id into the URL next/previous link.
* @param string $morehtml More html content to output just before the nav bar.
* @param int $shownav Show Condition (navigation is shown if value is 1).
- * @param string $fieldid Name of field id into database to use for select next and previous (we make the select max and min on this field). Use 'none' to disable next/prev.
+ * @param string $fieldid Name of field id into database to use for select next and previous (we make the select max and min on this field compared to $object->ref). Use 'none' to disable next/prev.
* @param string $fieldref Name of field ref of object (object->ref) to show or 'none' to not show ref.
* @param string $morehtmlref More html to show after ref.
* @param string $moreparam More param to add in nav link url. Must start with '&...'.
@@ -6194,7 +6194,7 @@ class Form
if ($shownav)
{
//print "paramid=$paramid,morehtml=$morehtml,shownav=$shownav,$fieldid,$fieldref,$morehtmlref,$moreparam";
- $object->load_previous_next_ref((isset($object->next_prev_filter)?$object->next_prev_filter:''),$fieldid,$nodbprefix);
+ $object->load_previous_next_ref((isset($object->next_prev_filter)?$object->next_prev_filter:''), $fieldid, $nodbprefix);
$navurl = $_SERVER["PHP_SELF"];
// Special case for project/task page
diff --git a/htdocs/core/tpl/commonfields_add.tpl.php b/htdocs/core/tpl/commonfields_add.tpl.php
index 203ba67f3db..f6aebd6357c 100644
--- a/htdocs/core/tpl/commonfields_add.tpl.php
+++ b/htdocs/core/tpl/commonfields_add.tpl.php
@@ -26,7 +26,9 @@
foreach($object->fields as $key => $val)
{
- if (abs($val['visible']) != 1) continue; // Discard such field from form
+ // Discard if extrafield is a hidden field on form
+ if (abs($val['visible']) != 1) continue;
+
if (array_key_exists('enabled', $val) && isset($val['enabled']) && ! $val['enabled']) continue; // We don't want this field
print '