Kendo Validation isn't firing on button click

1.8k Views Asked by At

I have validation on a div's contents, and they are a bunch of inputs and dropdownlists, and I can't get the validation to work at all.. On the document.ready I hydrate the dropdownlists and go from there, but when I click on my submit button, the validation doesn't fire and I am not getting any console errors either

My markup is

<div class="container">
    <div class="form-horizontal">
        <div class="col-md-3"></div>
        <div class="col-md-6">
            <div class="col-md-12">

                <div id="FARInfo">

                    <div class="row">
                        <div class="form-group">
                            <center><h1 style="font-weight:bold; color:#1d5f86">Create Alert</h1></center>
                        </div>
                    </div>

                    <div class="row">
                        <div class="form-group">
                            <div class="col-md-4">
                                <input id="ddState" class="form-control max-size" name="state" required validationMessage="Required" />
                                <span class="k-invalid-msg" data-for="state"></span>
                            </div>

                            <div class="col-md-8">
                                <input id="ddCounty" class="form-control max-size topMargin" name="county" required validationMessage="Required" />
                                <span class="k-invalid-msg" data-for="county"></span>
                            </div>

                        </div>
                    </div>

                    <div class="row">
                        <div class="form-group">
                            <div class="col-md-12">
                                <input id="ddDepartment" class="form-control max-size" name="department" required validationMessage="Required" />
                                <span class="k-invalid-msg" data-for="department"></span>
                            </div>
                        </div>
                    </div>

                    <div class="row">
                        <div class="form-group">
                            <div class="col-md-12">
                                <input id="ddDistrict" class="form-control max-size" name="district" required validationMessage="Required" />
                                <span class="k-invalid-msg" data-for="district"></span>
                            </div>
                        </div>
                    </div><!-- End District -->

                    <div class="row">
                        <div class="form-group">
                            <div class="col-md-12">
                                <input type="text" id="txtReporter" class="form-control" name="reporter" placeholder="Reporter" required validationMessage="Required" style="max-width:100%;" />
                                <span class="k-invalid-msg" data-for="reporter"></span>
                            </div>
                        </div>
                    </div><!-- End Reporting Party -->

                    <div class="row">
                        <div class="form-group">
                            <div class="col-md-12">
                                <input type="text" id="txtAddress" class="form-control" name="address" placeholder="Address" required validationMessage="Required" style="max-width:100%;" />
                                <span class="k-invalid-msg" data-for="address"></span>
                            </div>
                        </div>
                    </div><!-- End Address -->

                    <div class="row">
                        <div class="form-group">
                            <div id="Cancel" class="col-md-6">
                                <div class="form-control" id="CancelFAR" style="background-color:#1D5F86; color:white; font-weight:bold">
                                    <center><a href="@Url.Content("~/Home/Index")" style="text-decoration:none; color:white;">Cancel</a></center>
                                </div>
                            </div>
                            <div class="col-md-6">
                                <button class="btn btn-block btn-success" id="SubmitFAR">
                                    Submit
                                </button>
                            </div>
                        </div>
                    </div>

                </div>

            </div>
        </div>
        <div class="col-md-3"></div>
    </div>
</div>

my document.ready is (minus the other functions in it)

$(document).ready(function () {
    var validator = $('#FARInfo').kendoValidator();

});

and my button click event is

$('#SubmitFAR').on('click', function () {
var validator = $("#FARInfo").kendoValidator().data("kendoValidator");

if(validator.validate()){
    SubmitFAR();

}

});

1

There are 1 best solutions below

0
On

You need the var validator = $("#FARInfo").kendoValidator().data("kendoValidator"); only once. But this isn't really a prolem.

I rebuild your source and can't reproduce your error, for me your required-validators work. Maybe you loaded your scripts in the wrong way?

Take a look: https://dojo.telerik.com/OyUFu