1

I have a dialog into form that containing three input text fields.

When validation fire then that focus on first validation failed input text field. e.g In the second field if no value is input or is left empty then focus on second field.

I have try <p:focus> but it's not working on dialog but working fine in simple page.

<p:dialog id="dlg" widgetVar="dlg" resizable="false" dynamic="true"
    draggable="true" modal="true" showEffect="clip" hideEffect="clip"
    appendTo="@(body)" onShow="adjustPositionning(this.id)" closable="true"
    header="Heading">
    <p:ajax event="close" listener="#{bean.resetData()}"
        update=":uploadfrm"></p:ajax>
    <h:form id="uploadfrm" enctype="multipart/form-data">
        <p:focus></p:focus>
        <h:panelGrid id="detailPnl" columns="3">
            <p:outputLabel for="Name" value="Name" />
            <p:inputText id="CndName" maxlength="190" value="#{bean.vo.name}"
                required="true" />
            <p:message for="CndName" showDetail="true" />

            <p:outputLabel for="email" value="Email" />
            <p:inputText id="eamils" maxlength="290" value="#{bean.vo.email}"
                required="true">
                <f:validator validatorId="EmailValidator" />
            </p:inputText>
            <p:message for="eamils" showDetail="true" />

            <p:outputLabel for="MobileNoLbl" value="Mobile No" />
            <p:inputText id="MobileNo" maxlength="290" value="#{bean.vo.no}">
            </p:inputText>
            <p:message for="MobileNo" showDetail="true" />

            <div align="center">
                <p:commandButton value="save" id="saveBtn"
                    styleClass="btn btn-sm btn-success" title="Save"
                    update="uploadfrm :frm" validateClient="true"
                    action="#{bean.onSubmit()}"
                    oncomplete="if(!args.validationFailed)dlg.hide();"
                    onstart="modalDialog.show()" onsuccess="modalDialog.hide();" />
                <p:spacer width="10" />
                <p:commandButton value="Cancel" id="cancelBtn"
                    styleClass="btn btn-sm btn-default" title="Cancel"
                    update="detailPnl" actionListener="#{bean.resetData()}"
                    oncomplete="dlg.hide();" immediate="true">
                    <p:resetInput target=":uploadfrm" />
                </p:commandButton>
            </div>
    </h:form>
</p:dialog>

suggest me other solution for this appreciable for me when using JavaScript or primefaces.

Note: Script should be client side I don't want to change my Java Code.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Divyesh Kanzariya
  • 3,629
  • 3
  • 43
  • 44

0 Answers0