Kendo ui dropdownlist validation mvc

Kendo ui dropdownlist validation mvc

The required validation of Kendo UI DropDownList not working some time so I'm going to share the code below for solving the same issues.




Table of Contents
      
  1. jQuery code sample.
  2. HTML 5 code sample.





Step 1 : for jquery example
//This is used for validate to KendoDropDownList.

function validateKendoDropDownList(e) {

    e.preventDefault();

    var validator = $("#formSubmit").kendoValidator().data('kendoValidator');

    var isValid = false;

    if (!(validator.validate())) {

        $("#lblMessage").text('Please select a tenant...');

        isValid = true;

    }

    return isValid;

}



$(document).ready(function () {

    $('#btnRegisterToACompany').click(function (e) {

        var isRequired = validateKendoDropDownList(e);

        if (!isRequired) {

            submtRegisterToACompany();

        }

    });

});

Step 1 : for HTML 5 code

<div id="formSubmit">
   <section class="well" style="height: 250px !important">     
       <div class="form-horizontal form-widgets col-sm-6"> 
           <label id="lblMessage" style="color:red;"></label>       
           <div class="form-group">
               <label for="language" class="control-label col-sm-4">Tenant</label>
               <div class="col-sm-8 col-md-6">
                   <input id="ddlTenants" />
               </div>
           </div>
           <div class="form-group">
               <label for="language" class="control-label col-sm-4">Company</label>
               <div class="col-sm-8 col-md-6">
                   <input id="ddlCompany" required />
               </div>
           </div>
           <div class="form-group">
               <label for="language" class="control-label col-sm-4"></label>
               <div class="col-sm-8 col-md-6 text-align_right">
                   <input type="button" value="Register to a company" id="btnRegisterToACompany" class="btn btn-primary" />
               </div>
           </div>
       </div>
    </section>
</div>



ANIL SINGH

Anil Singh is an author, tech blogger, and software programmer. Book writing, tech blogging is something do extra and Anil love doing it. For more detail, kindly refer to this link..

My Tech Blog - https://www.code-sample.com/
My Books - Book 1 and Book 2

Kendo ui dropdownlist validation mvc Kendo ui dropdownlist validation mvc Reviewed by Anil Singh on 9:19 AM Rating: (5)
www.code-sample.com/. Powered by Blogger.
^