Fix server side auto-repeat to have different rows, instead of multiple references to the same one

This commit is contained in:
Nathan Gray 2013-07-17 09:38:37 +00:00
parent df0dc0f27a
commit 5f0ac7a70b
3 changed files with 24 additions and 2 deletions

View File

@ -620,6 +620,16 @@ class etemplate_widget
return '['.get_class($this).'] ' .
$this->type.($this->attrs['type'] && $this->attrs['type'] != $this->type ? '('.$this->attrs['type'].')' : '').'#'.$this->id;
}
/**
* When cloning a widget, we also clone children
*/
public function __clone()
{
foreach($this->children as $child_num => $child) {
$this->children[$child_num] = clone $child;
}
}
/**
* Convert widget (incl. children) to xml

View File

@ -95,6 +95,7 @@ class etemplate_widget_grid extends etemplate_widget_box
call_user_func_array(array($this, $method_name), $params);
}
//foreach($this->children as $n => $child)
$repeat_child = null;
for($n = 0; ; ++$n)
{
// maintain $expand array name-expansion
@ -110,11 +111,23 @@ class etemplate_widget_grid extends etemplate_widget_box
if (isset($this->children[$n]))
{
$child = $this->children[$n];
if($this->type == 'rows' || $this->type == 'columns')
{
/*
* We store a clone of the repeated child, because at the end
* of this loop the function $method_name is run on $child.
* We want to run the function again each repeat, on an unmodified
* row / column.
*/
$repeat_child = clone $child;
}
}
// check if we need to autorepeat last row ($child)
elseif (isset($child) && ($this->type == 'rows' || $this->type == 'columns') && $child->need_autorepeat($cname, $expand))
{
// not breaking repeats last row/column ($child)
// Clone the repeating child, to avoid modifying it
$child = clone $repeat_child;
}
else
{

View File

@ -54,8 +54,7 @@ class etemplate_widget_tabbox extends etemplate_widget
*/
public function validate($cname, array $expand, array $content, &$validated=array())
{
$form_name = $cname;
$form_name = self::form_name($cname, $this->id, $expand);
if (!$this->is_readonly($cname, $form_name))
{
$value = self::get_array($content, $form_name);