<div class="modal fade" id="CrearSerie" tabindex="-1" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
                <h4 class="modal-title caption-subject font-blue-secondary sbold uppercase">Crear Serie</h4>
            </div>
            <div class="modal-body">
                <?php echo e(Form::open(array('id' => 'form-validationN','route' => 'registrar.caja.serie', 'class'=>'form-horizontal'))); ?>

                <div class="form-body">
                    <div class="form-group">
                        <label class="control-label col-md-2" for="serie"> Serie </label>
                        <div class="col-md-10"><?php echo Form::text('serie', null, array('placeholder' => '','class' => 'form-control', 'required' => 'required', 'maxlength' => '4','onkeypress' => 'return isNumberKey(event)','onpaste' => 'return false')); ?></div>
                    </div>
                    <div class="form-group">
                        <label class="control-label col-md-2" for="correlativo"> Correlativo </label>
                        <div class="col-md-10"><?php echo Form::text('correlativo', null, array('placeholder' => '','class' => 'form-control', 'required' => 'required', 'maxlength' => '6','onkeypress' => 'return isNumberKey(event)','onpaste' => 'return false')); ?></div>
                    </div>
                    <div class="form-actions">
                        <div class="row">
                            <div class="col-md-offset-2 col-md-10">
                                <button type="button" class="btn btn-default" data-dismiss="modal">Cancelar</button>
                                <button id="submitBtn" type="submit" class="btn btn-primary ladda-button" data-style="slide-down">
                                    <span class="ladda-label">Guardar</span>
                                    <span class="ladda-spinner"></span>
                                </button>
                            </div>
                        </div>
                    </div>
                </div>
                <?php echo Form::close(); ?>

            </div>
        </div>
    </div>
</div>
<script>
    $("#form-validationN").validate({
        submitHandler: function (form) {
            var l = Ladda.create(document.querySelector('#submitBtn'));
            l.start();
            $.ajax({
                url:  $(form).attr('action'),
                type: 'POST',
                data: $(form).serialize(),
                cache: false,
                success: function(data) {
                    $('#CrearSerie').modal('toggle');
                    if (data == "error") {
                        swal("No se puedo crear la serie", "Inténtelo de nuevo", "error");
                    } else {
                        swal("Serie creada", "Se creo satisfactoriamente", "success");
                        $select = $('#series_select');
                        var valor = data.id+'-'+data.correlativo;
                        $select.append($('<option />', {value: valor, text: data.serie}));

                        $('#series_select > option[value="'+valor+'"]').attr('selected','selected');

                        $("#ccorrelativo").val(data.correlativo);
                        $("#Pserie").val(data.id);
                    }
                },
                error: function(data) {
                    swal("No se pudo crear", "Ocurrió un error al realizar su solicitud.", "error");
                },
                complete: function() {
                    l.toggle();
                }
            });
        }
    });

    function isNumberKey(evt){
        var charCode = (evt.which) ? evt.which : event.keyCode
        if (charCode > 31 && (charCode < 48 || charCode > 57))
            return false;
        return true;
    }

</script>