IE Primefaces Enter Key Submit Closes Dialog

UI Components for JSF
Post Reply
cgswtsu78
Posts: 53
Joined: 25 Jan 2011, 19:18

11 Apr 2011, 00:36

Hello,

I've run into and issue with IE not allowing me to hit the enter key to submit a form. I found a partial solution (http://www.thefutureoftheweb.com/blog/s ... with-enter) but my dialog window closes. My validations are run and the error messages are displayed. How would I keep my dialog open?

Code: Select all

<p:dialog id="sgupdlg" header="#{bundle['signUp.HEADER']}" widgetVar="signUpDlg"
    		modal="true" styleClass="dialog dialog1" draggable="false"
    		resizable="false" showEffect="fade" hideEffect="fade" position="top">
    		<h:form id="signUpFrm" binding="#{signUpDetail.signUpFrm}">
    		<p:growl id="growl" showDetail="true" showSummary="false" life="3000" errorIcon="/images/Validation-Error.png" infoIcon="/images/Validation-Success.png"/> 
    		
    		<p:inputText value="#{signUpDetailBean.firstName}" name="nameInput" required="true" requiredMessage="First Name is Required"/>
    		<p:inputText value="#{signUpDetailBean.lastName}" required="true" requiredMessage="Last Name is Required"/>	
    					
    		<p:commandButton styleClass="form-btn2"
    						value="#{bundle['signUp.button.LABEL']}" actionListener="#{signUpDetail.signUp}" onclick="trackingSignUpOverlaySave()" 
    						oncomplete="handleSignUpRequest(xhr, status, args)" update="growl"/>
    		<p:commandButton type="reset" styleClass="close" />
    				
    		</h:form>
    	</p:dialog>
    	<script type="text/javascript">  
    	     
    	   
    		$ = jQuery
    		$(function(){
    		    $('input').keydown(function(e){
    		        if (e.keyCode == 13) {
    		        	$('#signUpFrm').submit();
    		            return false;
    		        }
    		    });
    		});
    		
    	  
    	</script>  

User avatar
bumble.bee
Posts: 723
Joined: 29 Sep 2010, 21:39
Location: United States

11 Apr 2011, 15:03

Sounds like you need to conditionally close your dialog based on whether the form inside the dialog passed validation or not. There is an example of this in the showcase here:

http://www.primefaces.org/showcase/ui/dialogLogin.jsf

The basic idea is to use callback parameters. Note: in the showcase example, they add a new one, however, there is already one named validationFailed that is always automatically added by PrimeFaces so you don't actually need to add a new one. You just need to create a client side method that is called using the oncomplete attribute of your submit button in the dialog.

healeyb
Posts: 365
Joined: 07 Apr 2010, 16:05

11 Apr 2011, 16:46

I recently tried validationFailed in 2.2.1 and couldn't get it to work, I
just defined my own callback parameter instead. Perhaps I was doing
something silly, best to give it a try and if you have any problems you
have been warned.

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 25 guests