rich:表单提交的热键?
我有一个看起来像这样的登录表单,使用 RichFaces 和 Seam:
<h:form id="loginForm">
<h:outputLabel value="Username" />
<h:inputText value="#{identity.credentials.username}" />
<h:outputLabel value="Password" />
<h:inputText value="#{identity.credentials.password}" />
<h:commandLink action="#{identity.login()}" value="Login" />
</h:form>
我希望能够允许用户点击“回车”并自动提交表单进行登录。我尝试过使用 Richfaces 的
功能,但我认为我做错了什么。我输入的代码如下所示:
<rich:hotKey key="return"
handler="#{rich:element('loginForm')}.submit()" />
但是,当我在表单内按 Enter 键时,什么也没有发生。知道我在这里做错了什么吗?
I've got a login form that looks something like this, using RichFaces and Seam:
<h:form id="loginForm">
<h:outputLabel value="Username" />
<h:inputText value="#{identity.credentials.username}" />
<h:outputLabel value="Password" />
<h:inputText value="#{identity.credentials.password}" />
<h:commandLink action="#{identity.login()}" value="Login" />
</h:form>
I'd like to be able to allow the user to hit 'enter' and automatically submit the form to login. I've tried using Richfaces' <rich:hotKey />
feature, but I think I'm doing something wrong. The code I've put in looks like this:
<rich:hotKey key="return"
handler="#{rich:element('loginForm')}.submit()" />
However, when I hit enter inside the form, nothing happens. Any idea what I'm doing wrong here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为你需要使用选择器属性。比如,
另外,您应该单击提交按钮,而不是提交表单。像这样的东西,
I think you need to use selector property. Something like,
Also, instead of submitting the form, you should click submit button. Something like,
尝试以下代码。我希望你能得到一些想法..
Try the following code. I hope you can get some idea..
对于所有仍在为这个问题苦苦挣扎的人,我终于得到了一些有用的东西。我的代码现在如下所示:
您还可以使用更具体的选择器,以便仅当焦点位于表单字段之一时按 Enter 键才会提交表单。不管怎样,这终于解决了我的问题。
For all those still struggling with this issue, I've finally gotten something that works. My code now looks like this:
You can also use a more specific selector so that an enter press only submits the form when the focus is on one of the form fields. Either way, this FINALLY solved my problem.