0

I have a dialog form popup when I click one button, this form is used to create a new school record with just one field. I have add required validation to this only input field, and everything works fine, but the only thing I don't know how to do is when I click submit, whatever form validate or not, the dialog will dismiss by following code:

 initDataTable();
    // Dismiss the dialog
    $('#dialogNewSchool').dialog('close');

before the dialog close, I should put the form validation check (something like the return from validation class), how I can do this in javascript? I'm using JSF 2.1 implementation.

Btw, I don't want to use client side validation, because not only required validation needed for this field.

Thanks. ;)

lastcow
  • 137
  • 1
  • 4
  • 13
  • Post the code you have tried. – Rong Nguyen Sep 23 '13 at 01:48
  • possible duplicate of [Keep p:dialog up when a validation error occurs after submit](http://stackoverflow.com/questions/9195756/keep-pdialog-up-when-a-validation-error-occurs-after-submit) – BalusC Sep 23 '13 at 01:54

1 Answers1

0

If I got you right you want to keep dialog open in case of validation errors?

Than you can add the following code somewhere in your page

<h:panelGroup id="global_flag_validation_failed_render">
    <h:outputText id="global_flag_validation_failed" value="true" rendered="#{facesContext.validationFailed}"/>
</h:panelGroup>

And upon clicking your submit button render the above block like this:

<f:ajax onevent="closeMyDialogIfAllOk" render="@form global_flag_validation_failed_render"></f:ajax>

and in your js code

function closeMyDialogIfAllOk(data){
    if(data.status === 'success') {
        if($("#global_flag_validation_failed").length === 0){
             $("#dialog_id").dialog("close");
        }
    }
}

For more info take a look over here: How to find indication of a Validation error (required=“true”) while doing ajax command

Community
  • 1
  • 1
Daniel
  • 36,833
  • 10
  • 119
  • 200