voyent
Making ace:pushButton default for a form  XML
Forum Index -> Components
Author Message
kdean

Joined: 12/May/2009 00:00:00
Messages: 37
Offline


I have a simple login form: ace:textEntry for the email address, h:inputSecret for the password, ace:checkBoxButton for "Remember me", ace:pushButton for "OK", and ace:pushButton for "Cancel".

I would like the user to be able to login by pressing ENTER in the password field. In fact, I would like a general purpose "trigger this button when ENTER is pressed" capability. I cannot, however, find any reference anywhere as to how to do that.

Any help on this would be much appreciated.
khandada

Joined: 16/Feb/2009 00:00:00
Messages: 5
Offline


Hey, I am not sure about the ace componets but you can achive this from the javascript.
If javascript is ok then you have to capture key events and if the event is related to enter then you have to submit the respective form.
[Email]
khandada

Joined: 16/Feb/2009 00:00:00
Messages: 5
Offline


This is the sample code snippet
<input type="text" onkeyup="inputKeyUp(event)">

function inputKeyUp(event) {
if (event.which == 13 || event.keyCode == 13) {
// submit the form/ genrate the click event
var tb = document.getElementById("sometextbox");
eval(tb.value);
tb.click();
}
}
[Email]
mircea.toma

Joined: 10/Feb/2005 00:00:00
Messages: 323
Offline


ICEfaces is not the one to decide which button should be clicked when Enter key is pressed. This logic has to be wired into the application. One way is to use Javascript, not the greatest approach since you will have to know alot about ICEfaces internals and might be difficult to maintain the code in the future.

Another way is to wire the logic on the server side using event listeners. Something like this should do:
Code:
 <ace:textEntry label="User name" .... valueChangeListener="#{bean.login}"/>
 <ace:textEntry label="Password" .... valueChangeListener="#{bean.login}"/>
 <ace:pushButton value="OK" action="#{bean.login}"/>
 <ace:pushButton value="Cancel" action="#{bean.cancelLogin}"/>
 


kdean wrote:
I have a simple login form: ace:textEntry for the email address, h:inputSecret for the password, ace:checkBoxButton for "Remember me", ace:pushButton for "OK", and ace:pushButton for "Cancel".

I would like the user to be able to login by pressing ENTER in the password field. In fact, I would like a general purpose "trigger this button when ENTER is pressed" capability. I cannot, however, find any reference anywhere as to how to do that.

Any help on this would be much appreciated. 
[Email]
kdean

Joined: 12/May/2009 00:00:00
Messages: 37
Offline


That doesn't look like it would work, though I may be misunderstanding ICEfaces. First of all, the ValueChangeListener could be fired by something other than the ENTER key (e.g. on blur when tabbing or mousing out of the field). Also, since it's not part of the JSF flow, how do I then direct the user to the "successful login" page?
JanD

Joined: 18/Sep/2012 13:11:54
Messages: 2
Offline


When pressing Enter on an h:inputText or an ace:textEntry, it only submits the content of the field but does not invoke an actual form submit (e.g., invoking the action of the first button).
This also clears the displayed value of an h:inputSecret, unless redisplay="true" is specified (which I now have, but hopefully only as a workaround).

This does not seem right. Is this behaviour expected? Am I missing an option to define something like a default action for an entire form?
ken.fyten

Joined: 26/Oct/2004 00:00:00
Messages: 1332
Offline


Hi,

By default, the ICEfaces 3.x bridge will submit the form whenever the "enter" key is pressed inside an input component in the form (that the component itself doesn't trap). However, this feature doesn't trigger any button actions to work, so you wouldn't get the action event from a button for this.

Currently, the ace:textEntry component doesn't trigger an event when enter is pressed. This could be added fairly readily though, and exposed as a new client event on the component for a future release.

For now, though, you will likely need to add a JavaScript event listener for the enter keydown event on the textEntry component and have it trigger the desired button to do the submit.

Regards,
Ken



Ken Fyten
VP Product Development
ICEsoft Technologies, Inc.
JanD

Joined: 18/Sep/2012 13:11:54
Messages: 2
Offline


I have tried that. In my case, however, the desired button was "clicked" (via JavaScript) and the field was submitted (default behaviour). Consequently, when invalid input is entered, I get an error message for about half a second (first ajax update), which is removed immediately by the second ajax update.


How can I prevent the default ajax action?
ken.fyten

Joined: 26/Oct/2004 00:00:00
Messages: 1332
Offline


I think if you consume/cancel the enter key event by having your keyDown event listener return "false;", that will prevent the default bridge behaviour when the user presses enter.


Ken Fyten
VP Product Development
ICEsoft Technologies, Inc.
ken.fyten

Joined: 26/Oct/2004 00:00:00
Messages: 1332
Offline


Hi,

There is also a JIRA for a new component/tag to enable configuration of which action/button to trigger when enter is pressed:

http://jira.icesoft.org/browse/ICE-8498

Please vote for it and we'll try to get this in for 3.3.

Regards,
Ken

Ken Fyten
VP Product Development
ICEsoft Technologies, Inc.
kdean

Joined: 12/May/2009 00:00:00
Messages: 37
Offline


Voted. Thanks.
 
Forum Index -> Components
Go to:   
Powered by JForum 2.1.7ice © JForum Team