[Dojo-interest] post bug with multiple params?

James Burke jburke at dojotoolkit.org
Tue Aug 28 00:16:21 UTC 2007


On 8/27/07, Paulo Siqueira <paulo.siqueira at gmail.com> wrote:
> > However, using a form that has multiple fields with the same name will
> > not send all of the values for that name. That issue is being tracked
> > in this bug:
> > http://trac.dojotoolkit.org/ticket/4259
>
> This is what broke my application. I'll keep an eye on this issue, thank
> you.
>  Any chance this will be fixed soon? Or I'm better working around this?

It is scheduled to be fixed for 1.0, but I am not sure when I will get
to it. Here is a replacement function that *may* work, but it is
totally untested:

dojo.formToObject = function(/*DOMNode||String*/ formNode){
	var ret = {};
	var iq = "input[type!=file][type!=submit][type!=image][type!=reset][type!=button],
select, textarea";
	dojo.query(iq, formNode).filter(function(node){
		return (!node.disabled);
	}).forEach(function(item){
		var _in = item.name;
		var type = (item.type||"").toLowerCase();
		if((type == "radio")||(type == "checkbox")){
			if(item.checked){ ret[_in] = item.value; }
		}else if(item.multiple){
			var ria = ret[_in] = [];
			dojo.query("option[selected]", item).forEach(function(opt){
				ria.push(opt.value);
			});
		}else{
			//START of patch
			var _iv = ret[_in];
			if(_iv){
				if(typeof _iv == "string"){
					ret[_in] = [];
					ret[_in].push(_iv);
				}
				ret[_in].push(item.value);
			}else{
				ret[_in] = item.value;
			}
			//END of patch
			if(type == "image"){
				ret[_in+".x"] = ret[_in+".y"] = ret[_in].x = ret[_in].y = 0;
			}
		}
	});
	return ret;
}


James


More information about the Dojo-interest mailing list