If two widgets have the same ID, and they both return objects as values (eg: link widgets) then merge the values instead of replacing

This commit is contained in:
Nathan Gray 2012-07-04 22:41:51 +00:00
parent f1ea3db040
commit 9a6e3d59a8
3 changed files with 19 additions and 4 deletions

View File

@ -195,6 +195,12 @@ class etemplate_widget_nextmatch extends etemplate_widget
{
$value['col_filter'][$parent_id] = $queriedRange['parent_id'];
}
// If specific data requested, just do that
if (($row_id = $value['row_id']) && $queryiedRange['refresh'])
{
$value['col_filter'][$row_id] = $queriedRange['refresh'];
}
$rows = $result['data'] = $result['order'] = array();
$result['total'] = self::call_get_rows($value, $rows, $result['readonlys']);
$result['lastModification'] = egw_time::to('now', 'ts')-1;

View File

@ -1178,7 +1178,7 @@ var et2_link_add = et2_inputWidget.extend({
},
doLoadingFinished: function() {
this._super.apply(this, arguments);
this.app_select = et2_createWidget("link-apps", this.options ,this);
this.app_select = et2_createWidget("link-apps", jQuery.extend({},this.options,{'id': this.options.id + 'app'}) ,this);
this.div.append(this.app_select.getDOMNode());
this.button = et2_createWidget("button", {label: this.egw().lang("add")}, this);
this.button.set_label(this.egw().lang("add"));

View File

@ -404,18 +404,27 @@ etemplate2.prototype.getValues = function(_root)
id = typeof _target == "undefined" ? 0 : Object.keys(_target).length;
}
var value = _widget.getValue();
// Check whether the entry is really undefined
if (typeof _target[id] != "undefined")
if (typeof _target[id] != "undefined" && (typeof _target[id] != 'object' || typeof value != 'object'))
{
egw.debug("error", _widget, "Overwriting value of '" + _widget.id +
"', id exists twice!");
}
// Store the value of the widget and reset its dirty flag
var value = _widget.getValue();
if (value !== null)
{
_target[id] = value;
// Merge, if possible (link widget)
if(typeof _target[id] == 'object' && typeof value == 'object')
{
_target[id] = jQuery.extend([],_target[id],value);
}
else
{
_target[id] = value;
}
}
else if (jQuery.isEmptyObject(_target))
{