从 Tapestry 中的 JavaScript 函数内部提交表单
我正在尝试从 Tapestry 中的 JavaScript 函数内部提交表单。 这是 tml 文件。
<!DOCTYPE html>
<html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd" xmlns:tx="tapestry-library:tapx">
<head>
<script type="text/javascript">
function bodyLoaded () {
document.form1.submit();
}
</script>
</head>
<body onload="bodyLoaded()">
<form t:type="form" t:name="form1">
<select t:type="select" t:id="reportType" t:model="literal:A, B"></select>
<input t:type="submit" id="clientSubmit" value="Generate"/>
</form>
</body>
</html>
但我收到以下错误,并且表单未提交。
document.form1 未定义 [中断 这个错误] document.form1.submit();
于是我查看了Tapestry生成的html代码。它有以下标签:
<form onsubmit="javascript:Tapestry.waitForPage(event);"
action="test.form" method="post" id="form" name="form">
所以我将 document.form1.submit() 更改为 document.form.submit(),但仍然没有解决问题。我的代码有什么问题吗(或者)hibernate 不允许从 JavaScript 函数内部提交表单?
I am trying to submit a form from inside a JavaScript function in Tapestry.
Here is the tml file.
<!DOCTYPE html>
<html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd" xmlns:tx="tapestry-library:tapx">
<head>
<script type="text/javascript">
function bodyLoaded () {
document.form1.submit();
}
</script>
</head>
<body onload="bodyLoaded()">
<form t:type="form" t:name="form1">
<select t:type="select" t:id="reportType" t:model="literal:A, B"></select>
<input t:type="submit" id="clientSubmit" value="Generate"/>
</form>
</body>
</html>
But I am getting below error, and the form is not getting submitted.
document.form1 is undefined [Break on
this error] document.form1.submit();
So I looked at the html code generated by Tapestry. It has following tag:
<form onsubmit="javascript:Tapestry.waitForPage(event);"
action="test.form" method="post" id="form" name="form">
So I changed document.form1.submit() to document.form.submit(), but still it didn't solve the problem. Is there anything wrong with my code (or) doesn't hibernate allow to submit the form from inside JavaScript functions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
升级到 Tapestry 5.2。这是之前 5.x 版本中的一个已知问题。
https://issues.apache.org/jira/browse/TAP5-947
upgrade to tapestry 5.2. this was a known issue in prior 5.x versions.
https://issues.apache.org/jira/browse/TAP5-947
我刚刚将 id 放入表单标签中,并在 java 脚本中进行了一项更改。
这可能对你有帮助。
谢谢。
i have just put id in the form tag and one change in java script.
This may help you.
Thanks.
而不是
document.form
尝试document.forms[0]
instead of
document.form
trydocument.forms[0]
我今天将 Tapestry 从 5.0.1.5 更新到 5.0.1.8,以摆脱 AjaxFormLoop 中烦人的错误,猜猜我遇到了什么:)
在沮丧了近 4 个小时后,我尝试了一些有效的方法。
该错误是由 Tapestry 自动在表单的 onSubmit 事件上添加 waitForPage(event) javascript 方法引起的(以防止在加载页面之前提交表单)。当您说
document.getElementById('form1').submit();
或此处注释建议的任何迭代时,它似乎会由于方法参数不匹配而抛出该异常(我思考)。无论如何,要修复它,只需将行更改为document.getElementById('form1').submit(this);
这对我有用,我希望这也能解决您的问题!
I updated tapestry today from 5.0.1.5 to 5.0.1.8 to get rid of the annoying bug in AjaxFormLoop, and guess what I ran into :)
After being frustrated for almost 4 hours I tried something that worked.
The error is caused by Tapestry automatically adding a waitForPage(event) javascript method on the form's onSubmit event (to prevent the form from being submitted before the page is loaded). When you say
document.getElementById('form1').submit();
or any of its iterations suggested by the comments here, it seems to throw that exception because of a mismatch in the method arguments (I think). Anyway to fix it just change the line todocument.getElementById('form1').submit(this);
This worked for me and I hope this solves your problem as well!