表单观察提交不起作用?
我已经读过多次,这是在提交表单时添加客户端回调的推荐方法,但它对我不起作用:
<t:form t:id="myForm" id="myForm">
<t:submit />
</t:form>
<script type="text/javascript">
$("myForm").observe(Tapestry.FORM_PREPARE_FOR_SUBMIT_EVENT, function() {
alert("submitting");
});
alert("listening");
</script>
有人可以指出我做错了什么吗?
我正在使用挂毯 5.1.0.5
I've read multiple times that this is the recommended approach to adding client side callbacks when a form is submitted, however it isn't working for me:
<t:form t:id="myForm" id="myForm">
<t:submit />
</t:form>
<script type="text/javascript">
$("myForm").observe(Tapestry.FORM_PREPARE_FOR_SUBMIT_EVENT, function() {
alert("submitting");
});
alert("listening");
</script>
Can someone point out what I have done wrong?
I'm using tapestry 5.1.0.5
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
5.1.0.5 中有一个有趣的缺陷(在较新的版本中已修复)
一个简单的页面仅不会导致任何核心问题
要加载的 Tapestry javascript 库(tapestry.js、prototype.js 等)因此表单甚至没有挂接 onSubmit。向表单中的字段添加验证可以解决此问题,但如果您没有字段,那就很难了。
如果您甚至没有在页面中加载 Tapestry.js,那么第一步就是确保您正在做的事情会告诉框架您想要它。一种方法是调用 RenderSupport#addScript。传递空字符串将被忽略,因此您可以在其中添加分号以本质上获得无操作。
接下来要做的事情是在表单元素上调用 getFormEventManager 来初始化挂毯的表单,并确保附加事件处理程序。
我还更新了 TML 以等待 dom 加载,这样您就不会遇到奇怪的计时错误:
令人讨厌,但在框架的更高版本中修复了。
There is an interesting defect in 5.1.0.5 (fixed in newer versions)
A simple page with only doesn't cause any of the core
tapestry javascript libraries to load (tapestry.js, prototype.js, etc) So the form is not even hooking onSubmit. Adding validation to a field in the form would fix this, but if you don't have a field that's hard.
If you don't even have tapestry.js loading in the page then the first step is to make sure you're doing something that will tell the framework you want it. One way to do this is by calling RenderSupport#addScript. Passing an empty string is ignored so you can stick a semi-colon in it to essentially get a no-op.
The next thing to do would be to call getFormEventManager on your form element to initialize the form for tapestry, and make sure the event handlers are attached.
I also updated the TML to wait for the dom to load so you don't get strange timing errors:
Obnoxious, but fixed in later versions of the framework.