From 1dc6376ed4a75afc83dca065f8f45599ea0ba48b Mon Sep 17 00:00:00 2001 From: Nathan Gray Date: Fri, 23 Mar 2012 18:17:15 +0000 Subject: [PATCH] Handle inputs with names ending in [] as arrays --- etemplate/js/etemplate2.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/etemplate/js/etemplate2.js b/etemplate/js/etemplate2.js index 10bd3ae9b8..7e3ff8a4a5 100644 --- a/etemplate/js/etemplate2.js +++ b/etemplate/js/etemplate2.js @@ -315,10 +315,11 @@ etemplate2.prototype.getValues = function(_root) // check if id contains a hierachical name, eg. "button[save]" var id = _widget.id; - var indexes = _widget.id.split('[',2); // Discards the others + var indexes = id.split('['); if (indexes.length > 1) { - indexes[1] = _widget.id.substring(indexes[0].length+1, _widget.id.length-1); // Add the rest back in, less the trailing ] + indexes = [indexes.shift(), indexes.join('[')]; + indexes[1] = indexes[1].substring(0,indexes[1].length-1); var children = indexes[1].split(']['); if(children.length) { @@ -351,6 +352,12 @@ etemplate2.prototype.getValues = function(_root) } } + // Handle arrays, eg radio[] + if(id === "") + { + id = typeof target == "undefined" ? 0 : _target.length; + } + // Check whether the entry is really undefined if (typeof _target[id] != "undefined") {