How to validate a hidden empty field in jquery steps with a function true

Viewed 198

I have some fields that write themselves as I use the form, all the fields are hidden I would like to know how to make jquery validate validate that the field is not empty

this is the input

<input id="location_id" type="number"
class="form-control" name="location_id">

and this is the jquery steps

$(document).ready(function () {
            $("#digest-report-form").steps({
                bodyTag: "section",
                transitionEffect: "slideLeft",
                stepsOrientation: "horizontal",
                onStepChanging: function (event, currentIndex, newIndex) {
                   
                    if (currentIndex > newIndex) {
                        return true;
                    }

                   

                    var form = $(this);

                    if (currentIndex < newIndex) {
                       
                        $(".body:eq(" + newIndex + ") label.error", form).remove();
                        $(".body:eq(" + newIndex + ") .error", form).removeClass("error");
                    }

                   
                    form.validate().settings.ignore = ":disabled,:hidden";

                   
                    return form.valid();
                },
                onStepChanged: function (event, currentIndex, priorIndex) {
                    
                },
                onFinishing: function (event, currentIndex) {
                    var form = $(this);

                    
                    form.validate().settings.ignore = ":disabled";

                    
                    return form.valid();
                },
                onFinished: function (event, currentIndex) {
                    var form = $(this);

                    form.validate().settings.ignore = ":disabled";

                    
                    if (form.valid()) {
                        var json = convertFormToJSON(form);
                        console.log(json);
                        form.submit();
                    }
                }
            }).validate({
                errorPlacement: function (error, element) {
                    
                    error.insertAfter(element.parent());
                },
            });

I made a function that checks if the field is empty or not, I am trying to add it to jquery steps

    function checkLocationEmpty() {
        if (document.getElementById("location_id").value.length == 0) {
            return true;
        }
        return false;
    }
1 Answers

I solved, I just added my function into OnStepChanging and return false

if (locationEmpty) {
   $('#alert_location_empty').show();
   setTimeout(function () {
   $('#alert_location_empty').hide();
                        }, 3000);
   return false;
                    }
Related