如何在 Tapestry5 中更新区域后设置焦点
我有一个区域,其中包含一个包含循环的表单。当有人更改循环中的文本字段时,它会更新 onKeyUp 事件上的整个表单和循环。
我正在尝试找到一种方法来告诉 Tapestry 将焦点返回到上次更新的文本字段。我想我已经完成了这项工作,但是区域更新似乎使文本字段在设置焦点后立即失去焦点。我可以毫无问题地将焦点设置到区域之外的字段,因此似乎是区域更新导致了问题。
关于如何处理这个问题有什么建议吗?
I have a zone that contains a form that contains a loop. When someone changes a text field within the loop, it updates the entire form and loop on the onKeyUp event.
I am trying to find a way to tell Tapestry to return the focus to the text field that was last updated. I think I have this working, but the zone update appears to make the text field lose focus immediately after the focus is set. I can set the focus to a field that is outside of the zone without a problem, so it appears to be the zone update that is causing the issue.
Any suggestions on how to handle this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
听起来您需要在区域重新加载完成后设置焦点。每当我需要执行这样的任务时,我都会设置一个观察者来侦听 Javascript 中的 Tapestry 区域更新事件:
希望这会有所帮助。
Sounds like you need to set the focus after the zone is done reloading. Whenever I need to do a task like that I set up an observer that listens for the Tapestry zone-updated event in Javascript:
Hope this helps.
我知道这是一个旧线程,但我所做的是:
使用 jquery:
这将集中在第一个空输入或选择上。当然你的页面上必须包含jquery。 noConflict 确保您不会遇到原型问题。
I know this is an old thread, but what I did was:
Using jquery:
This will get focus on first empty input or select. Of course you have to include jquery on your page. noConflict makes sure you wont have problems with prototype.
Form 组件有一个
autofocus
参数默认为 true,导致一些 JavaScript 与表单一起呈现。表单加载后,JS 将焦点设置到第一个表单元素。将
autofocus
设置为false
会禁用此行为:The Form component has an
autofocus
parameter which is true by default, causing a bit of JavaScript to be rendered with the form. The JS sets the focus to the first form element after the form has loaded.Setting
autofocus
tofalse
disables this behaviour: