Encode square brackets and split names at ][, not just [

This commit is contained in:
Nathan Gray 2011-11-14 22:57:06 +00:00
parent 89fdaa7691
commit 26c888ccd4
5 changed files with 64 additions and 13 deletions

View File

@ -423,14 +423,14 @@ class etemplate_widget
{ {
foreach($value as &$val) foreach($value as &$val)
{ {
$val = "'".str_replace(array("'",'"'),array('\\\'','"'),$val)."'"; $val = "'".str_replace(array("'",'"','[',']'),array('\\\'','"','[',']'),$val)."'";
} }
$value = '[ '.implode(', ',$value).' ]'; $value = '[ '.implode(', ',$value).' ]';
$name = str_replace("'".$matches[1]."'",$value,$name); $name = str_replace("'".$matches[1]."'",$value,$name);
} }
else else
{ {
$value = str_replace(array("'",'"'),array('\\\'','"'),$value); $value = str_replace(array("'",'"','[',']'),array('\\\'','"','[',']'),$value);
$name = str_replace(array('{'.$matches[1].'}',$matches[1]),$value,$name); $name = str_replace(array('{'.$matches[1].'}',$matches[1]),$value,$name);
} }
} }
@ -465,6 +465,7 @@ class etemplate_widget
$name = self::get_array($cont,substr($name,1)); $name = self::get_array($cont,substr($name,1));
} }
} }
$name = str_replace(array('[',']'),array('[',']'),$name);
return $name; return $name;
} }
@ -526,7 +527,10 @@ class etemplate_widget
*/ */
static function form_name($cname,$name) static function form_name($cname,$name)
{ {
$name_parts = explode('[',str_replace(']','',$name)); if (count($name_parts = explode('[', $name, 2)) > 1)
{
$name_parts = array_merge(array($name_parts[0]), explode('][', substr($name_parts[1],0,-1)));
}
if (!empty($cname)) if (!empty($cname))
{ {
array_unshift($name_parts,$cname); array_unshift($name_parts,$cname);
@ -534,7 +538,7 @@ class etemplate_widget
$form_name = array_shift($name_parts); $form_name = array_shift($name_parts);
if (count($name_parts)) if (count($name_parts))
{ {
$form_name .= '['.implode('][',$name_parts).']'; $form_name .= '['.implode('][',$name_parts).']';
} }
return $form_name; return $form_name;
} }
@ -559,7 +563,10 @@ class etemplate_widget
} }
if (is_object($idx)) return false; // given an error in php5.2 if (is_object($idx)) return false; // given an error in php5.2
$idxs = explode('[',str_replace(']','',$idx)); if (count($idxs = explode('[', $idx, 2)) > 1)
{
$idxs = array_merge(array($idxs[0]), explode('][', substr($idxs[1],0,-1)));
}
$pos = &$arr; $pos = &$arr;
foreach($idxs as $idx) foreach($idxs as $idx)
{ {

View File

@ -43,7 +43,17 @@ var et2_arrayMgr = Class.extend({
if (this.splitIds) if (this.splitIds)
{ {
for(var key in _data) { for(var key in _data) {
var indexes = key.replace(/]/g,'').split('['); var indexes = key.split('[');
if (indexes.length > 1)
{
indexes = [indexes.shift(), indexes.join('[')];
indexes[1] = indexes[1].substring(0,indexes[1].length-6);
var children = indexes[1].split('[]');
if(children.length)
{
indexes = jQuery.merge([indexes[0]], children);
}
}
if(indexes.length > 1) if(indexes.length > 1)
{ {
var value = _data[key]; var value = _data[key];
@ -142,7 +152,17 @@ var et2_arrayMgr = Class.extend({
if (this.splitIds) if (this.splitIds)
{ {
indexes = _key.replace(/]/g,'').split('['); indexes = _key.split('[');
if (indexes.length > 1)
{
indexes = [indexes.shift(), indexes.join('[')];
indexes[1] = indexes[1].substring(0,indexes[1].length-1);
var children = indexes[1].split('][');
if(children.length)
{
indexes = jQuery.merge([indexes[0]], children);
}
}
} }
var entry = this.data; var entry = this.data;

View File

@ -202,6 +202,11 @@ var et2_widget = Class.extend({
} }
} }
if(this.id)
{
this.id = this.id.replace(/\[/g,'[').replace(/]/g,']');
}
// Add all attributes hidden in the content arrays to the attributes // Add all attributes hidden in the content arrays to the attributes
// parameter // parameter
this.transformAttributes(_attrs); this.transformAttributes(_attrs);

View File

@ -195,6 +195,7 @@ var et2_button = et2_baseWidget.extend([et2_IInput, et2_IDetachedDOM], {
this.options.onclick = _values["onclick"]; this.options.onclick = _values["onclick"];
} }
this.btn.bind("click.et2_baseWidget", this, function(e) { this.btn.bind("click.et2_baseWidget", this, function(e) {
e.data.set_id(_values["id"]);
return e.data.click.call(e.data,e); return e.data.click.call(e.data,e);
}); });

View File

@ -211,6 +211,8 @@ etemplate2.prototype.submit = function(button)
if (canSubmit) if (canSubmit)
{ {
// Button parameter used for submit buttons in datagrid // Button parameter used for submit buttons in datagrid
// TODO: This should probably go in nextmatch's getValues(), along with selected rows somehow.
// I'm just not sure how.
if(button) if(button)
{ {
values.button = button.id values.button = button.id
@ -223,7 +225,17 @@ etemplate2.prototype.submit = function(button)
} }
if(target != values) if(target != values)
{ {
var indexes = button.id.replace(/]/g,'').split('['); var indexes = button.id.split('[');
if (indexes.length > 1)
{
indexes = [indexes.shift(), indexes.join('[')];
indexes[1] = indexes[1].substring(0,indexes[1].length-1);
var children = indexes[1].split('][');
if(children.length)
{
indexes = jQuery.merge([indexes[0]], children);
}
}
var idx = ''; var idx = '';
for(var i = 0; i < indexes.length; i++) for(var i = 0; i < indexes.length; i++)
{ {
@ -270,11 +282,17 @@ etemplate2.prototype.getValues = function(_root)
// check if id contains a hierachical name, eg. "button[save]" // check if id contains a hierachical name, eg. "button[save]"
var id = _widget.id; var id = _widget.id;
if (_widget.id.indexOf('[') != -1) var indexes = _widget.id.split('&#x5B;',2);
if (indexes.length > 1)
{ {
var parts = _widget.id.replace(/]/g,'').split('['); indexes = [indexes.shift(), indexes.join('&#x5B;')];
id = parts.pop(); indexes[1] = indexes[1].substring(0,indexes[1].length-6);
path = path.concat(parts); var children = indexes[1].split('&#x5B;&#x5D;');
if(children.length)
{
indexes = jQuery.merge([indexes[0]], children);
}
path = path.concat(indexes);
} }
// Set the _target variable to that node // Set the _target variable to that node