diff --git a/api/js/etemplate/et2_extension_customfields.ts b/api/js/etemplate/et2_extension_customfields.ts index d4abbc01ad..0103c23d73 100644 --- a/api/js/etemplate/et2_extension_customfields.ts +++ b/api/js/etemplate/et2_extension_customfields.ts @@ -368,10 +368,10 @@ export class et2_customfields_list extends et2_valueWidget implements et2_IDetac { for(let key in data) { - // Don't overwrite fields with global values - if(global_data[key] && key !== 'fields') + // Don't overwrite fields / customfields with global values + if(global_data[key] && key !== 'fields' && !(key == "customfields" && typeof data.customfields != undefined)) { - data[key] = jQuery.extend(true, {}, data[key], global_data[key]); + data[key] = {...data[key], ...global_data[key]}; } } } diff --git a/api/src/Etemplate/Widget/Customfields.php b/api/src/Etemplate/Widget/Customfields.php index ba4153bcb1..f3907aaecd 100644 --- a/api/src/Etemplate/Widget/Customfields.php +++ b/api/src/Etemplate/Widget/Customfields.php @@ -170,6 +170,17 @@ class Customfields extends Transformer $use_private = self::expand_name($this->attrs['private'] ?? null,0,0,'','',self::$cont); $this->attrs['type_filter'] = self::expand_name($this->attrs['type_filter'] ?? null,0,0,'','',self::$cont); + // check if name refers to a single custom field --> show only that + $matches = null; + if(($pos = strpos($form_name, $this->attrs['prefix'])) !== false && // allow the prefixed name to be an array index too + preg_match($preg = '/' . $this->attrs['prefix'] . '([^\]]+)/', $form_name, $matches) && isset($fields[$name = $matches[1]])) + { + $fields = array($name => $fields[$name]); + $value = self::get_array(self::$request->content, $form_name, false, true); + $fields[$name]['value'] = $value; + $form_name = $this->attrs['prefix'] . $name; + } + foreach((array)$fields as $key => $field) { // remove private or non-private cf's, if only one kind should be displayed @@ -192,16 +203,6 @@ class Customfields extends Transformer unset($fields[$key]); } } - // check if name refers to a single custom field --> show only that - $matches = null; - if (($pos=strpos($form_name,$this->attrs['prefix'])) !== false && // allow the prefixed name to be an array index too - preg_match($preg = '/'.$this->attrs['prefix'].'([^\]]+)/',$form_name,$matches) && isset($fields[$name=$matches[1]])) - { - $fields = array($name => $fields[$name]); - $value = self::get_array(self::$request->content, $form_name, false, true); - $fields[$name]['value'] = $value; - $form_name = $this->attrs['prefix'] . $name; - } if(!is_array($fields)) $fields = array(); switch($type = $this->type)