Better fix for tabs not being validated - handle it at the top level

This commit is contained in:
Nathan Gray 2013-06-11 18:59:34 +00:00
parent 6fcab842b0
commit c5a9952930
2 changed files with 53 additions and 4 deletions

View File

@ -277,6 +277,11 @@ class etemplate_widget
$class_name = 'etemplate_widget';
}
}
if(!$xml)
{
$xml = "<$type id='$id'/>";
}
//error_log(__METHOD__."('$type', ..., '$id') using $class_name");
// currently only overlays can contain templates, other widgets can only reference to templates via id
@ -380,6 +385,19 @@ class etemplate_widget
}
foreach($this->children as $child)
{
// If type has something that can be expanded, we need to expand it so the correct method is run
if(strpos($child->attrs['type'], '@') !== false || strpos($child->attrs['type'], '$') !== false)
{
$type = self::expand_name($child->attrs['type'],$expand['c'], $expand['row'], $expand['c_'], $expand['row_'], $expand['cont']);
$id = self::expand_name($child->id,$expand['c'], $expand['row'], $expand['c_'], $expand['row_'], $expand['cont']);
$attrs = $child->attrs;
unset($attrs['type']);
$expanded_child = self::factory($type, false,$id);
$expanded_child->id = $id;
$expanded_child->type = $type;
$expanded_child->attrs = $attrs + array('type' => $type);
$child = $expanded_child;
}
$child->run($method_name, $params, $respect_disabled);
}
}
@ -791,6 +809,7 @@ class etemplate_widget
public function &setElementAttribute($name,$attr,$val)
{
$ref =& self::$request->modifications[$name][$attr];
$this->attrs[$attr] = $val;
if (!is_null($val)) $ref = $val;
//error_log(__METHOD__."('$name', '$attr', ".array2string($val).')');

View File

@ -14,8 +14,35 @@
/**
* eTemplate Tabs widget stacks multiple sub-templates and lets you switch between them
*/
class etemplate_widget_tabbox extends etemplate_widget_box
class etemplate_widget_tabbox extends etemplate_widget
{
/**
* Fill additional tabs
*
* @param string $cname
*/
public function beforeSendToClient($cname)
{
if($this->attrs['tabs'])
{
$this->children[1]->children = array();
foreach($this->attrs['tabs'] as $tab)
{
if($tab['id'])
{
$template= clone etemplate_widget_template::instance($tab['template']);
$template->attrs['content'] = $tab['id'];
$this->children[1]->children[] = $template;
unset($template);
/* This doesn't work for some reason
$tab_valid =& self::get_array($validated, $tab['id'], true);
$tab_valid = $content[$tab['id']];
*/
}
}
}
}
/**
* Validate input - just pass through, tabs doesn't care
*
@ -41,16 +68,19 @@ class etemplate_widget_tabbox extends etemplate_widget_box
}
// Make sure additional tabs are processed
$this->children[1]->children = array();
foreach($this->attrs['tabs'] as $tab)
{
if($tab['id'] && $content[$tab['id']])
{
$template= clone etemplate_widget_template::instance($tab['template']);
$template->attrs['content'] = $tab['id'];
$this->children[1]->children[] = $template;
unset($template);
/* This doesn't work for some reason
$template = etemplate_widget_template::instance($tab['template']);
$template->run('validate', array($tab['id'], $expand, $content, &$validated), true);
*/
$tab_valid =& self::get_array($validated, $tab['id'], true);
$tab_valid = $content[$tab['id']];
*/
}
}
$valid = $value;