0

I have this code:

<p:commandButton value="Modal" type="button" onclick="PF('dlg').show();" />

<p:dialog header="Modal Dialog" widgetVar="dlg" modal="true" height="100">
            <h:outputText value="This is a Modal Dialog." />
            <p:inputText id="input" value="#{bean.text}" required="true"/>
        </p:dialog> 

If I press the enter key when the dialog is shown without fill the required field "input", the dialog is closed and the required validation for my inputText is not working. Can anyone tell me what I'm doing wrong?

Thank you all.

rlopezo
  • 425
  • 5
  • 16
  • java != javascript ! – StackFlowed Jan 31 '18 at 15:49
  • 1
    @Deoxyseia has a point. The submisstion is not automagically prevented. So either do as is in the comment or try if adding PrimeFaces client-side validation helps – Kukeltje Feb 01 '18 at 07:26
  • 1
    See also "Default action to execute when pressing enter in a form": https://stackoverflow.com/questions/5485851/default-action-to-execute-when-pressing-enter-in-a-form – Jasper de Vries Feb 01 '18 at 12:58

1 Answers1

1

Put closable true and in the input text for attribute onkeypress for enter keycode is 13, this works for me.

    <!--in dialog --> closable="true"
    <!--in inputText--> onkeypress="if (event.keyCode == 13) {
                                     return false;
                                 }"//in input text