You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Brian Duchek <ma...@gmail.com> on 2007/01/26 03:36:14 UTC

Re: Submit doesnt tag or select when the form is submitted via ajax

Hi Jesse: I'm stuck on Tap3 and a dated build of Tacos trying to get
around this problem.  I'm pretty sure that the problem is in Tacos.js,
so I'll include that code here.

Can you look at the below and help me find the tweak that will allow
the request body to include the "which submit button was clicked"
component name?  I'm using a bunch of buttons to submit the form that
look like this:

<button title="Next" name="step" type="submit">

Thanks!
~brian duchek
================================================================
var PartPost = function(form, parts) {
	var url = form.action;
	var headers = [];
	headers["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8";
	var values = FormUtil.getValues(form);

	// FIXME: once Form.getLink is exposed in Tapestry 3.0.4, replace the following
	// with: values["service"] += "/" + parts.join("/");
	var s = values["service"][0].split("/");
	s[0] = "partial";
	if (s.length==4) s.splice(3,0,s[2]);
	s = s.concat(parts);
	values["service"][0] = s.join("/");
	
	var body = FormUtil.encodeValues(values);

	OO.extend(this, new HttpRequest(url, "POST", body, headers));
	this.parts = parts;
};

PartPost.prototype.started = PartRequest.prototype.started;
PartPost.prototype.failed = PartRequest.prototype.failed;
PartPost.prototype.completed = PartRequest.prototype.completed;

//
// Form support
//

var FormUtil = new Object();

FormUtil.getElements = function(form) {
	var tags = ["input","textarea","select"];
	var elements = [];
	for (ti in tags) {
		var e = form.getElementsByTagName(tags[ti]);
		for (var ei=0; ei<e.length; ei++) {
			elements.push(e[ei]);
		}
	}
	return elements;
};

FormUtil.getValues = function(form) {
	var elements = FormUtil.getElements(form);
	var values = [];
	for (ei in elements) {
		var e = elements[ei];
		var value = FormUtil.getElementValue(e);
		if (value) {
           if (values[e.name] == null) values[e.name] = [];
           values[e.name].push(value);
		}
	}
	return values;
};

FormUtil.getElementValue = function(element) {
	switch (element.tagName.toLowerCase()) {
		case "textarea":
			return element.value;			
		case "input":
			switch (element.type.toLowerCase()) {
				case 'hidden':
				case 'password':
				case 'text':
					return element.value;
				case 'checkbox':
				case 'radio':
					return element.checked ? element.value : null;
			}
			break;
		case "select":
			var i = element.selectedIndex;
			return (i==-1) ? "" : element.options[i].value;		
	}
	return null;
};

FormUtil.encodeValues = function(values) {
	var body = "";
	var separator = "";
	for (name in values) {
		for (value in values[name]) {
			body += separator + encodeURIComponent(name)
					+ "=" + encodeURIComponent(values[name][value]);
			separator = "&";
		}
	}
	return body;
};

================================================================


On 8/21/06, Jesse Kuhnert <jk...@gmail.com> wrote:
> Yes, it is resolved. In the next few minutes at least. (Speaking of Forms
> with async only of course, the selected/tag has been working..)
>
> On 8/21/06, Pedro Viegas <pv...@gmail.com> wrote:
> >
> > I have saw that the JIRA has been stamped solved. ("Resolved. (both
> > handling
> > of selected/tag correctly and LinkSubmit working with ajax forms)")
> > It was done so on the 19th, same date as the last SNAPSHOT available on
> > maven rep.
> > The question is... has this fix been before or after the SNAPSHOT build of
> > the 19th?
> > It still happens! :-S
> >
> > Help!
> >
> > On 8/16/06, Josh Long <st...@gmail.com> wrote:
> > >
> > > Yay JIRA and Jesse!
> > >
> > > Um... the bug URL is https://issues.apache.org/jira/browse/TAPESTRY-1069
> > >
> > > Thanks again,
> > >
> > > Josh
> > >
> > > On 8/16/06, Jesse Kuhnert <jk...@gmail.com> wrote:
> > > > Hmm....Sounds like a JIRA worthy bug. (The fix is very easy though..I
> > > think?
> > > > ...will know later)
> > > >
> > > > On 8/16/06, Josh Long <st...@gmail.com> wrote:
> > > > >
> > > > > Im noticing that the  @Submit doesnt tag or select anything when the
> > > > > form is submitted via ajax (ie, async = true, updateComponents =
> > > > > "foo", etc)..
> > > > >
> > > > > Anyone else have this problem?
> > > > >
> > > > > Any workarounds?
> > > > >
> > > > > Peace,
> > > > > Josh
> > > > >
> > > > >
> > ---------------------------------------------------------------------
> > > > > To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> > > > > For additional commands, e-mail: users-help@tapestry.apache.org
> > > > >
> > > > >
> > > >
> > > >
> > > > --
> > > > Jesse Kuhnert
> > > > Tapestry/Dojo/(and a dash of TestNG), team member/developer
> > > >
> > > > Open source based consulting work centered around
> > > > dojo/tapestry/tacos/hivemind.
> > > >
> > > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> > > For additional commands, e-mail: users-help@tapestry.apache.org
> > >
> > >
> >
> >
> > --
> > Pedro Viegas
> >
> >
>
>
> --
> Jesse Kuhnert
> Tapestry/Dojo/(and a dash of TestNG), team member/developer
>
> Open source based consulting work centered around
> dojo/tapestry/tacos/hivemind.
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org