2396
Views
19
Comments
Solved
Disabling the Enter Key
Question
Has anybody ever needed to disable the Enter key for one screen? Or for an entire oml?
I'm asking because some users are complaining that when they hit Enter, it triggers the default button and they don't want that.
Staff
Rank: #12
Solution
Hi all,

Gonçalo you have two ways of doing this. Using javascript or using a dummy button. With javascript you'll have the implement the event handler onkeyup of every input and when the key of the event is chr(10) return false on that function. This is messy.

The second way is to have a default button on the page (you must always have one because of the default action of the webform that is triggered by the ENTER on the input). Make that default button invisible assign it to the current screen (you have to assign a destination to the button) and to prevent any postback include an handler for the onclick event with the code 'return false;' this will prevent the action of the button to be completed, meaning no postback is done.

I hope this helps you.

Cheers,
André
Rank: #338
Hi Gonçalo,

The simplest solution I can think of (maybe not the most elegant mind you!) is to have an invisible button on your screen with the "Default" property to "On" and no actions on its flow.

Cheers,
Hermínio
Rank: #414

Hi,

Another solution is set the "Defualt" property to "No" on each button and link of the screen, if there are no defualt, the enter key do nothing.

Nelson Inácio
Thanks Herminio and Nelson.

Herminio's suggestion works well, although it has to be done in every screen.
Nelson's suggestion only works in FireFox, has IE completely "destroys" the screen if you have no default button and press ENTER. As anybody figured a way to avoid this "destruction" ?
Rank: #338
Gonçalo,

I tried building a new webblock with only an invisible button on it, setting this button to default (even tough I think it will be irrelevant) and placing it on a screen with other content. Then I disabled the Default property of the widgets on that screen and it worked fine in both IE8 and Firefox 3.5.

It still implies using this block on every screen but its easier now. :)

This was done in 5.0! I don't know your version but it may be worth a shot.
Staff
Rank: #12
Solution
Hi all,

Gonçalo you have two ways of doing this. Using javascript or using a dummy button. With javascript you'll have the implement the event handler onkeyup of every input and when the key of the event is chr(10) return false on that function. This is messy.

The second way is to have a default button on the page (you must always have one because of the default action of the webform that is triggered by the ENTER on the input). Make that default button invisible assign it to the current screen (you have to assign a destination to the button) and to prevent any postback include an handler for the onclick event with the code 'return false;' this will prevent the action of the button to be completed, meaning no postback is done.

I hope this helps you.

Cheers,
André
Hi André,

That's what I did, thank you. I also used the suggestion Herminio gave, using that button in a web block.
Thank you all.
Staff
Rank: #188
If you don't want to change every screen, you can always add this to your eSpace Javascript:

osjs(document).ready(function() {
 osjs('form').prepend('<input type="submit" onclick="return false;" style="display:none;" />');
});

It will silently add an invisible submit button to the start of the form element. Pressing the enter key will trigger that button, which will not submit due to onclick returning false.

If you the page has a button with the default property set, that button will still be invoked upon pressing enter (therefore overriding the javascript hack). This may be useful if you have too many screens and are unwilling to put a webblock for this purpose on every single one.

Hope it helps!
Miguel,

I doesn't seem to work. Don't I need to add an ID to the button and write the CLASS attribute with the Is_Default style ?
mvp_badge
MVP
Rank: #28
The samples above doesn't work on current platform (8), does anyone have a solution for disabling enter key?
Staff
Rank: #29
Hi Matthias,

The one posted by Miguel should work unless you have a button set to default on your screen.
Can you post a sample or a link with a page with it not working?

Regards,
João Rosado
mvp_badge
MVP
Rank: #28
Forgot to refresh the browser, it script posted by Miguel does work indeed!
mvp_badge
MVP
Rank: #28
mmm.. it did work in Chrome but not in IE9, look like the (document).ready(function() is not fired in IE.
Staff
Rank: #29
Check if there are no other javascript errors on your page.
The jquery ready is the base of all jquery script/plugins ...a lot of other stuff would be broken if that didn't work.

Regards,
João Rosado
Rank: #821

Hi all,

I copied the JavaScript solution suggested by Miguel Ventura, and that alone didn't do the job. Then I set Default to No for the buttons involved, and that worked.

But we are a couple of years and a few versions further now ... does anyone know if there is a more elegant solution available in version 10? Preferably working in all modern (versions of the) browsers?


Rank: #1235

Hello guys, FYI, I used this to disable an enter for a input wigdet:

I was wondering, if I want to use the same disability for the all eSpace. I tryed the code above but it didn't work.

Rank: #8488

In the marked solution above ....it says: ..."to prevent any postback include an handler for the onclick event with the code 'return false;' this will prevent the action of the button to be completed, meaning no postback is done. "

First:  I don't see whereand how  in the Properties pane I can connect this onclick event to a handler.....can anyone tell me in practical terms what steps are needed here to fill in......  (Use in OS Traditional Web app)


Secondly : Depending on the browser does this suppress the POST of the whole page when the Enter key

                    is hit in the screen from within any Input field in this same screen?

- Thx for any assistance offered