diff --git a/etemplate/inc/class.boetemplate.inc.php b/etemplate/inc/class.boetemplate.inc.php
index e1e4be9d8b..ab98c6579e 100644
--- a/etemplate/inc/class.boetemplate.inc.php
+++ b/etemplate/inc/class.boetemplate.inc.php
@@ -764,6 +764,19 @@
return $this->widget_tree_walk('get_widget_by_name_helper',$name);
}
+ /**
+ * returns an array of references to widgets of the specified tipe
+ * @param type String
+ */
+ function &get_widgets_by_type($type) {
+ $extra = array(
+ 'type' => $type,
+ 'widgets' => array()
+ );
+ $this->widget_tree_walk('get_widgets_by_type_helper', $extra);
+ return $extra['widgets'];
+ }
+
/**
* generated a file-name from an eTemplates, name, template(-set) and lang
*
@@ -979,4 +992,12 @@
//echo "
path_searched='$extra', widget-path($widget[type]:$widget[name])='$path'
\n";
if ($path == $extra) return $widget;
}
+
+ function &get_widgets_by_type_helper(&$widget, &$extra)
+ {
+ //echo '
get_widgets_by_type_helper(' . $widget['name'] . ',' . $extra['type'] . ')
';
+ if($widget['type'] == $extra['type']) {
+ $extra['widgets'][] =& $widget;
+ }
+ }
}
diff --git a/etemplate/inc/class.uietemplate.inc.php b/etemplate/inc/class.uietemplate.inc.php
index c4dcf03bb5..630ddf2c9f 100644
--- a/etemplate/inc/class.uietemplate.inc.php
+++ b/etemplate/inc/class.uietemplate.inc.php
@@ -450,6 +450,28 @@ foreach($sess as $key => $val)
$GLOBALS['egw_info']['etemplate']['loop'] |= !$this->canceled && $this->button_pressed &&
$this->validation_errors($session_data['ignore_validation']); // set by process_show
+ // If a tab has an error on it, change to that tab
+ foreach($GLOBALS['egw_info']['etemplate']['validation_errors'] as $form_name => $msg)
+ {
+ $name = $this->template_name($form_name);
+ if (!$this->get_widget_by_name($name))
+ {
+ foreach($this->get_widgets_by_type('tab') as $widget)
+ {
+ foreach(explode('|',$widget['name']) as $tab)
+ {
+ if (strpos('.',$tab) === false) $tab = $this->name.'.'.$tab;
+ $tab_tpl = new etemplate($tab);
+ if ($tab_tpl->get_widget_by_name($name))
+ {
+ $content[$widget['name']] = $tab;
+ break 3;
+ }
+ }
+ }
+ }
+ }
+
//echo "process_exec($this->name) process_show(content) ="; _debug_array($content);
//echo "process_exec($this->name) session_data[changes] ="; _debug_array($session_data['changes']);
$content = $this->complete_array_merge($session_data['changes'],$content);
@@ -850,6 +872,27 @@ foreach($sess as $key => $val)
return $form_name;
}
+ /**
+ * strip the prefix of a form-element from a form_name
+ * This function removes the prefix of form_name(). It takes a name like base[basesub1][basesub2][name][sub]
+ * and gives basesub1[basesub2][name][sub]
+ *
+ * @param string form_name
+ * @return string name without prefix
+ */
+ function template_name($form_name)
+ {
+ $parts = explode('[',str_replace(']','',$form_name));
+
+ array_shift($parts); // remove exec
+
+ $name = array_shift($parts);
+
+ if ($parts) $name .= '['.implode('][',$parts).']';
+
+ return $name;
+ }
+
/**
* generates HTML for one widget (input-field / cell)
*