Validation with Parsley and Modal window

0

I have a problem and I can not resolve it. I have a button that when I click on it presents a message to the user of confirmation, it happens that before opening this modal I would like to validate if all fields are filled in.

For validation I'm using the Parsley

If I just use the simple button as below the validation is done successfully.

<button class="btn btn-primary" type="submit">Submit</button>

But if I use the button that calls the modal I can not use the validator before.

<button data-toggle="modal" data-target="#md-default" type="button" id="postar" class="btn btn-info btn-lg"><i class="fa fa-check"></i> <b>Enviar</b></button>


     <!-- Modal -->
                              <div class="modal fade" id="md-default" tabindex="-1" role="dialog">
                                 <div class="modal-dialog">
                                    <div class="modal-content">
                                       <div class="modal-header">
                                          <button type="button " class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                                       </div>
                                       <div class="modal-body">
                                          <div class="text-center">
                                             <div class="i-circle primary"><i class="fa fa-check"></i></div>
                                             <div class="confirmacao" id="confirmacao">
                                                <h4>Confirma o envio do Push?</h4>
                                             </div>
                                             <div class="resp"></div>
                                             <p></p>
                                          </div>
                                       </div>
                                       <div class="modal-footer">
                                          <button type="button" class="btn btn-default btn-flat" data-dismiss="modal" id="cancelButton" >Cancelar</button>
                                          <button type="submit" class="btn btn-primary btn-flat enviar" id="submitButton" >Sim</button>
                                          <button type="button" style="display: none" class="btn btn-default btn-flat" data-dismiss="modal" id = "closeButton">Fechar</button>
                                       </div>
                                    </div>
                                    <!-- /.modal-content -->
                                 </div>
                                 <!-- /.modal-dialog -->
                              </div>


    <!-- /.modal -->
    
asked by anonymous 13.09.2016 / 17:32

1 answer

1

First you will need to create a javascript file to validate your form with Parsley , shortly after, you will have to use Parsley itself to verify that the form has been validated successfully or not. p>

$(document).ready(function() {
var form = $("#form").parsley();
if (form.isValid()) {
    $("#myModal").modal("show");
   }
});
    
13.09.2016 / 18:06