Enter-key Prevention Javascript Not Working for JSF 1.1 in IE
Notes on environment: JSF 1.1 using Infragistics component library.
I'm using the following Javascript to attempt to prevent an 'Ent开发者_高级运维er' keypress from submitting a form.
function disableEnterKey(e){
var key;
if(window.event)
key = window.event.keyCode;
else
key = e.which;
return (key != 13);
}
Then in the JSP, I have:
<h:inputText id="an_id" value="#{bean.value}"
onkeypress="return disableEnterKey(event);" />
This seems to work flawlessly in Firefox and Google Chrome. I don't understand why it doesn't work with IE8. I'm stumped.
I've tried using a Tomahawk <t:inputText/>
, but that doesn't make a difference.
I've tried putting something in the onkeypress
handler for the parent <h:form>
and/or the <body>
element, but that doesn't seem to help either. And, I've tried using the onkeydown
, but haven't seen a difference with that, either.
The differential diagnosis that I think I have come up with is that it may have something to do with the Infragistics library. IG does add quite a bit of scripting to pages, but I'm not solid on how to debug Javascript effectively with IE8. This would be no problem to poke through with Firebug on FF, but I'm a bit stumped.
Anyone have a similar experience? Know of a fix?
I know it is bit late, but this is for others who try to do this thing.
This problem occurs if your page contains only one h:inputText
.
Add another like hidden text this resolves problem.
Example
<h:panelGroup>
<h:inputText id="test1" style="display: none;" styleClass="alignleft" value="" />
</h:panelGroup>
weird thing, because it works for me in IE8 and in FF only this way:
var key;
if(window.event)
{
//IE
key = window.event.keyCode;
}
else
{
//FF
key = e.keyCode;
}
This was the only way to solve this!
<h:inputText id="test1" style="display: none;" styleClass="alignleft" value="" />
精彩评论