diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php
index d20db100014..8230786c449 100644
--- a/htdocs/core/class/html.form.class.php
+++ b/htdocs/core/class/html.form.class.php
@@ -5723,7 +5723,6 @@ class Form
$lis='';
$listcheckedstring='';
- $array = dol_sort_array($array, 'position');
foreach($array as $key => $val)
{
/* var_dump($val);
diff --git a/htdocs/modulebuilder/template/myobject_list.php b/htdocs/modulebuilder/template/myobject_list.php
index 96c9967880c..fa06a7e7d05 100644
--- a/htdocs/modulebuilder/template/myobject_list.php
+++ b/htdocs/modulebuilder/template/myobject_list.php
@@ -134,7 +134,8 @@ if (is_array($extrafields->attribute_label) && count($extrafields->attribute_lab
if (! empty($extrafields->attribute_list[$key])) $arrayfields["ef.".$key]=array('label'=>$extrafields->attribute_label[$key], 'checked'=>(($extrafields->attribute_list[$key]<0)?0:1), 'position'=>$extrafields->attribute_pos[$key], 'enabled'=>(abs($extrafields->attribute_list[$key])!=3 && $extrafields->attribute_perms[$key]));
}
}
-
+$object->fields = dol_sort_array($object->fields, 'position');
+$arrayfields = dol_sort_array($arrayfields, 'position');